Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid, refresh listview on item clicked
    primarykey
    data
    text
    <p>I know their are a lot of question relative to refreshing listView, but none of them are anwering my problem (as far as I know).</p> <p><strong>I'm trying to change my item view when clicking on it in my list view.</strong></p> <p>To change the view I've got a <code>boolean isClicked</code> on my POJO :</p> <pre><code> networksListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; _adapter, View view, int pos, long id) { myApp.networksGlobal.networks.get(pos); myApp.networksGlobal.networks.get(pos).isClicked = !myApp.networksGlobal.networks.get(pos).isClicked; adapter.notifyDataSetChanged(); } }); </code></pre> <p>When I click on the item <code>isClicked</code> switch from true to false, and on my <code>getView</code> listAdapted I'm switching the view type :</p> <pre><code> @Override public View getView(int position, View convertView, ViewGroup parent) { Network network = (Network) getItem(position); NetworkItemView networkItemView; if (convertView == null) { networkItemView = NetworkItemView_.build(context); } else { networkItemView = (NetworkItemView) convertView; } networkItemView.bind(network); if (network.isClicked) { networkItemView.networkItemButtonLayout.setVisibility(View.VISIBLE); } else { networkItemView.networkItemButtonLayout.setVisibility(View.GONE); } return networkItemView; } </code></pre> <p>On the first click everything is working great, the Toast is shown an the Layout <code>networkItemButtonLayout</code> is set to visible.</p> <p>But if I click a second time on the same item : <strong>nothing happend</strong>. No Toast is shown and no changes on the Layout visibility.</p> <p>If I comment <code>adapter.notifyDataSetChanged()</code> the Toast is shown for every click. So I guess the problem is why the call to <code>adapter.notifyDataSetChanged()</code>. So tried several work around (<code>adapter.notifyDataSetChanged()</code> and <code>networksSearchListView.invalidateViews()</code>) but nothing do the trick, and I can't find a way to click several time on my item.</p> <p>Does I'm using 'notifyDataSetChanged' the proper way ?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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