简体   繁体   中英

Set 2 different images for two different empty listview in the same application

实际上,当我有单个列表时 ,我可以在我的应用程序中使用空的listview 。但是我遇到了两个使用相同xml的不同列表。是空的

Set the visibility of whatever image you want to VIEW.GONE when your list is not empty. You can then create two different images in your layout. Have them initially set to visible.

In the onCreate method check the ArrayList you are using for your adapter when loading the list to see if it is empty. If it is not empty then set the visibility of your image to VIEW.GONE. Then all you have to do is do this same check whenever there are deletions to the list. (because you can't get an empty list by adding more entries) And whenever you make an addition to the list set the visibility of the image to VIEW.VISIBLE . (so basically wherever you do a notify of a data change on the adapter)

Hopefully this logic helps out!

ImageView emptyListImage1 = (ImageView) findViewById(R.layout.image1);
ImageView emptyListImage2 = (ImageView) findViewById(R.layout.image2);

emptyListImage1.setVisibility(VIEW.GONE);
emptyListImage1.setVisibility(VIEW.VISIBLE);

If you are using imageview with id android.R.id.empty.

then simply use this

ImageView image=(ImageView)findviewbyid(android.R.id.empty);

and set the desired image.

Yep Akki that was almost correct with a little changes in my XMl.The Final code is here All I had to use the same textview described inside the list xml file.

        TextView tv=(TextView)findViewById(android.R.id.empty);
        tv.setBackgroundResource(R.drawable.anniversary_reminder);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM