Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to notifyDataSetChange() from onitemclick() method?
    primarykey
    data
    text
    <p>I have to change the the data in list view after clicking on each item Can any body please tell me how to notify the change after the item is clicked in list view. I am not using base adapter .I am using customized Adapter.Any help will be highly Appreciable. check my code.I am trying to add button on which position the user clicks.Is it possible .When I try click on the position It gives force close.following is my code.</p> <pre><code>public class CamNe extends Activity implements OnItemClickListener,OnItemSelectedListener{ /** Called when the activity is first created. */ String[] items={"lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", "adipiscing", "elit", "morbi", "vel", "ligula", "vitae", "arcu", "aliquet", "mollis", "etiam", "vel", "erat", "placerat", "ante", "porttitor", "sodales", "pellentesque", "augue", "purus"}; int pos=0; ListView ls; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView ls=(ListView)findViewById(R.id.list); //ls1=(ListView)findViewById(R.id.list); ls.setAdapter(new adapter(getApplicationContext(), items)); ls.setOnItemClickListener(this); } @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub pos=arg2; setTitle("mil"); ListAdapter ad=ls.getAdapter(); ((ArrayAdapter) ad).notifyDataSetChanged(); } class adapter extends ArrayAdapter{ private Context context; public adapter(Context context,String[] items) { super(context,R.layout.row,items); this.context=context; // TODO Auto-generated constructor stub } public View getView(int position, View convertView, ViewGroup parent) { View row=convertView; ViewWrapper wrapper; Button but = null; if (row==null) { LayoutInflater inflater = (LayoutInflater)context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); row=inflater.inflate(R.layout.row, null); wrapper=new ViewWrapper(row); row.setTag(wrapper); but=wrapper.getRatingBar(); but.setVisibility(4); if(position==pos){ but.setVisibility(0); } } else { wrapper=(ViewWrapper)row.getTag(); if(position==pos) but=wrapper.getRatingBar(); } wrapper.getLabel().setText(items[position]); if(position==pos){ but.setTag(new Integer(pos)); } return row; } } @Override public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub setTitle("mil"); pos=arg2; ((BaseAdapter) ls.getAdapter()).notifyDataSetChanged(); } @Override public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub } } </code></pre>
    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.
    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