Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ListView not refreshing after notifyDataSetChanged
    primarykey
    data
    text
    <p>My ListFragment code </p> <pre><code>public class ItemFragment extends ListFragment { private DatabaseHandler dbHelper; private static final String TITLE = "Items"; private static final String LOG_TAG = "debugger"; private ItemAdapter adapter; private List&lt;Item&gt; items; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.item_fragment_list, container, false); return view; } @Override public void onCreate(Bundle savedInstanceState) { super.setHasOptionsMenu(true); super.onCreate(savedInstanceState); getActivity().setTitle(TITLE); dbHelper = new DatabaseHandler(getActivity()); items = dbHelper.getItems(); adapter = new ItemAdapter(getActivity().getApplicationContext(), items); this.setListAdapter(adapter); } @Override public void onResume() { super.onResume(); items.clear(); items = dbHelper.getItems(); //reload the items from database adapter.notifyDataSetChanged(); } @Override public void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); if(dbHelper != null) { //item is edited Item item = (Item) this.getListAdapter().getItem(position); Intent intent = new Intent(getActivity(), AddItemActivity.class); intent.putExtra(IntentConstants.ITEM, item); startActivity(intent); } } } </code></pre> <p>My ListView</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>But this does not refresh the <code>ListView</code>. Even after restarting app the updated items are not shown. My <code>ItemAdapter</code> extends <code>BaseAdapter</code></p> <pre><code>public class ItemAdapter extends BaseAdapter{ private LayoutInflater inflater; private List&lt;Item&gt; items; private Context context; public ProjectListItemAdapter(Context context, List&lt;Item&gt; items) { super(); inflater = LayoutInflater.from(context); this.context = context; this.items = items; } @Override public int getCount() { return items.size(); } @Override public Object getItem(int position) { return items.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ItemViewHolder holder = null; if(convertView == null) { holder = new ItemViewHolder(); convertView = inflater.inflate(R.layout.list_item, parent,false); holder.itemName = (TextView) convertView.findViewById(R.id.topText); holder.itemLocation = (TextView) convertView.findViewById(R.id.bottomText); convertView.setTag(holder); } else { holder = (ItemViewHolder) convertView.getTag(); } holder.itemName.setText("Name: " + items.get(position).getName()); holder.itemLocation.setText("Location: " + items.get(position).getLocation()); if(position % 2 == 0) { convertView.setBackgroundColor(context.getResources().getColor(R.color.evenRowColor)); } else { convertView.setBackgroundColor(context.getResources().getColor(R.color.oddRowColor)); } return convertView; } private static class ItemViewHolder { TextView itemName; TextView itemLocation; } } </code></pre> <p>Can someone help please?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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