Hello everyone, I have a 3 activity app. The third activity displays a ListView with a custom Adapter. Data comes from a custom built List<T>. On the activity, I have 3 ToggleButtons and one ListView. Each togglebutton is supposed to change the content of the ListView.
I tried this differents ways (explained below), but the bug is always the same : the list does not get updated UNLESS I tap the HOME button, and then go back to the app. After doing this, my app is working fine, and the content is changing. Here's what I tried : - using 3 ListViews with 3 instances of my custom adapter. (the rest is with 1 ListView) - having 3 instances of my custom adapter, - having 1 instance of my custom adapter, changing the content, and calling notifyDataSetChanged(), - disabling the drawing caches (setDrawingCacheEnabled, setScrollingCacheEnabled), - calling invalidate(), requestLayout(), scrollTo() on the ListView... - extending my custom adapter from BaseAdapter and from ArrayAdapter, - extending my activity from ListActivity and using setListAdapter. None of the above worked. I must do something wrong, but what ? Here is some code : // my custom Adapter public class GroupedValueAdapter extends BaseAdapter { private Context mContext; private List<GroupedValue> mItems; public GroupedValueAdapter(Context context, List<GroupedValue> items) { mContext = context; mItems = items; } public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; if (row == null) { LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.listitem, null); } TextView label = (TextView) row.findViewById(R.id.txtItemLabel); GroupedValue group = (GroupedValue) this.getItem(position); label.setText(group.value); ImageView icon = (ImageView) row.findViewById(R.id.img1); icon.setVisibility(group.onFirst ? View.VISIBLE : View.GONE); icon = (ImageView) row.findViewById(R.id.img2); icon.setVisibility(group.onSecond ? View.VISIBLE : View.GONE); icon = (ImageView) row.findViewById(R.id.img3); icon.setVisibility(group.onThree ? View.VISIBLE : View.GONE); return row; } public int getCount() { return mItems.size(); } public void updateItems(List<GroupedValue> items) { mItems = items; notifyDataSetChanged(); } public Object getItem(int position) { return mItems.get(position); } public long getItemId(int position) { return position; } } In my activity : public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.viewpeoplegroup); Intent intent = getIntent(); mGroup = (PeopleGroup) intent .getSerializableExtra("com.digitrad.organip.PeopleGroup"); /* HEADER */ if (mGroup.photo.length() > 0) { setPhoto(); } TextView tv = (TextView) findViewById(R.id.txtPName); tv.setText(mGroup.name); tv = (TextView) findViewById(R.id.txtPLocation); tv.setText(mGroup.location); Button btn = (Button) findViewById(R.id.btnCall); btn.setOnClickListener(mFakeTabClickListener); btn = (Button) findViewById(R.id.btnInvite); btn.setOnClickListener(mFakeTabClickListener); btn = (Button) findViewById(R.id.btnVoicemail); btn.setOnClickListener(mFakeTabClickListener); /* LIST */ mList = getListView(); // mList.setAdapter(new GroupedValueAdapter(this, mGroup.numbers)); setListAdapter(new GroupedValueAdapter(this, mGroup.numbers)); mList.setDrawingCacheEnabled(false); mList.setScrollingCacheEnabled(false); if (mGroup.canInvite) { showList("INVITE"); } else if (mGroup.canEmail && mGroup.canCall == false) { showList("VOICEMAIL"); } else { showList("CALL"); } } private void showList(String s) { GroupedValueAdapter adapter = (GroupedValueAdapter) mList.getAdapter (); if (s == "CALL") { mList.setOnItemClickListener(mCallClickListener); adapter.updateItems(mGroup.numbers); } else if (s == "VOICEMAIL") { mList.setOnItemClickListener(mEmailClickListener); adapter.updateItems(mGroup.emails); } else if (s == "INVITE") { mList.setOnItemClickListener(mInviteClickListener); adapter.updateItems(mGroup.invites); } mList.invalidate(); mList.requestLayout(); mList.scrollTo(0, 0); } Let me remind you that everything works perfectly after going to HOME, and then going back to the activity. Until I do this, the ListView does not get updated. Help would be appreciated, Regards, --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---