سؤال

Actually I am able to use empty listview in my application when I am having Single list.But I am encountering with two different list which is using same xml.Now how should I proceed in order to get 2 different images to my different list when they are Empty,

هل كانت مفيدة؟

المحلول

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);

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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top