Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView with multiple View Types Not Refreshing Properly
    text
    copied!<p>I'm trying to create 3 distinct themes for my list view. I've verified that each theme will actually display the proper background layout and bind to the data objects. The problem I'm facing is that after switching the theme in the preferences and coming back to the main ViewActivity, often all the views will still have the old theme layout. Until I scroll up and down or change the phone orientation.</p> <p>The sequence of calls is onResume() -> updateUI() -> clear listview adapter, add new data to bind to, call dataSetChanged() -> custom getView() in adapter looks at the theme and selects the proper view accordingly.</p> <p>Below are a few pieces of code (I saw the type stuff in the Google IO video)...</p> <p>One of the theme's from getView()</p> <pre><code> // bind to the view if(convertView == null) convertView = vi.inflate(R.layout.viewrow, parent, false); iv = (ImageView) convertView.findViewById(R.id.viewrow_image); dt = (TextView) convertView.findViewById(R.id.viewrow_dayview); tt = (TextView) convertView.findViewById(R.id.viewrow_toptext); bt = (TextView) convertView.findViewById(R.id.viewrow_bottomtext); sImage = (ImageView) convertView.findViewById(R.id.viewrow_status); // adjust for batch mode if (model.isChecked()) convertView.setBackgroundColor(Color.LTGRAY); else convertView.setBackgroundResource(0); // adjust for completion if (model.isComplete()) { tt.setPaintFlags(tt.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); sImage.setImageResource(R.drawable.ctask); } else { tt.setPaintFlags(tt.getPaintFlags() &amp; ~Paint.STRIKE_THRU_TEXT_FLAG); sImage.setImageResource(R.drawable.ictask); } // adjust for priority String priority = model.getPriority(); if (priority.equals("IMMEDIATE")) iv.setImageResource(R.drawable.immediatepriorityicon); else if (priority.equals("HIGH")) iv.setImageResource(R.drawable.highpriorityicon); else if (priority.equals("MEDIUM")) iv.setImageResource(R.drawable.mediumpriorityicon); else iv.setImageResource(R.drawable.lowpriorityicon); // update priority preference if (!app.api.getCheckPriorityIcon()) iv.setVisibility(View.GONE); else iv.setVisibility(View.VISIBLE); // color day text long days = model.getDueIn(); if (days &gt; 0) { dt.setTextColor(Color.GREEN); } else if (days == 0) { dt.setTextColor(Color.WHITE); } else { dt.setTextColor(Color.RED); } // adjust for completion preference // 0 strike // 1 text // 2 invisible int cMode = app.api.getCompletionModeEvent(); switch (cMode) { case 0: sImage.setVisibility(View.GONE); break; case 1: tt.setPaintFlags(tt.getPaintFlags() &amp; ~Paint.STRIKE_THRU_TEXT_FLAG); sImage.setVisibility(View.VISIBLE); break; case 2: tt.setPaintFlags(tt.getPaintFlags() &amp; ~Paint.STRIKE_THRU_TEXT_FLAG); sImage.setVisibility(View.GONE); break; } break; </code></pre> <p>updateUIList() does:</p> <pre><code>protected void updateUIList() { eventAdapter.clear(); if(selectedDate == null) { if(app.api.getShowCompleteEvents()) allEvents = app.edo.getAllEvents(); else allEvents = app.edo.getIncompleteEvents(); if(eventFilter != null){ allEvents = eventFilter.filterEvents(allEvents); } allEvents = preferenceSort(allEvents); int count = 0; if(allEvents != null) count = allEvents.size(); setTitle(app.APP_TITLE + ": All Entries (" + count + ")"); } else { allEvents = preferenceSort(app.edo.searchByDate(selectedDate, !app.api.getShowCompleteEvents())); int count = 0; if(allEvents != null) count = allEvents.size(); setTitle(app.APP_TITLE + ": Entries on " + selectedDate + " (" + count + ")"); } // if we have no events, hide our list view and display the static "No Tasks" text, otherwise show it. if(allEvents == null) { emptyTextView.setVisibility(View.VISIBLE); eventContainer.setVisibility(View.GONE); return; } if(emptyTextView.getVisibility() == View.VISIBLE) { emptyTextView.setVisibility(View.GONE); } if(eventContainer.getVisibility() == View.GONE) { eventContainer.setVisibility(View.VISIBLE); } for(Event anEvent : allEvents) { eventAdapter.add(anEvent); } eventAdapter.notifyDataSetChanged(); } ` </code></pre> <p>and the theme types:</p> <pre><code> @Override public int getViewTypeCount() { // TODO should correspond to themes array return 3; } @Override public int getItemViewType(int position) { if(position == 0){ theme = app.api.getThemeView(); } return theme; } </code></pre> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload