Android ListView appears empty, but contains objects
Posted
by
Lethjakman
on Stack Overflow
See other posts from Stack Overflow
or by Lethjakman
Published on 2012-09-10T01:41:40Z
Indexed on
2012/09/10
3:38 UTC
Read the original article
Hit count: 511
I'm having a really odd problem with my android listview. The listview is inside of a fragment, everything's compiling and I'm no longer getting a nullpointer error, but the listview is appearing empty. Even though it's appearing empty, the log is stating that the listview has 385 objects. I can't figure out why it's empty. I do get a blue fragment, and the listview is populated. Any ideas?
How I set the adapter:
ActivePackages = getList();
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout mContainer = (LinearLayout) inflater.inflate(R.layout.tab_frag1_layout, null);
ListView activeList = (ListView) mContainer.findViewById(R.id.activelist);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, ActivePackages);
Log.i("valueof activeList",String.valueOf(activeList.getCount())); //returns 0
activeList.setAdapter(adapter);
adapter.notifyDataSetChanged();
Log.i("valueof activeList",String.valueOf(activeList.getCount())); //returns 385.
This is the xml for the fragment:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/activelist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0073fd">
</ListView>
</LinearLayout>
© Stack Overflow or respective owner