Note that there are some explanatory texts on larger screens.

plurals
  1. POlistview with button
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/11363366/handling-button-event-in-each-row-of-listview-issue">Handling button event in each row of Listview issue</a> </p> </blockquote> <p>I am working on an android app. I am supposed to add a button in each row of ListView and when I click any button I need the button should be removed. However when I do so, button is removed but some other buttons in other positions also removed. Furthermore when i scroll down and up the ListView these buttons which I clicked and removed again appear in the list. Could you please show me an exact solution or a completed piece of code? Thank you... </p> <pre><code>public View getView(final int position, View convertView, ViewGroup parent) { if(convertView == null){ // LayoutInflater class is used to instantiate layout XML file into its corresponding View objects. LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); convertView = layoutInflater.inflate(R.layout.listxml, null); } rawTextView = (TextView) convertView.findViewById(R.id.textView1); rawTextView.setText("Text "+innerClassBookArray[position]); final LinearLayout lnr=(LinearLayout)convertView.findViewById(R.id.layoutforbtn); final Button btn = new Button(getBaseContext()); btn.setText("MyButton"); btn.setId(position); lnr.addView(btn); btn.setOnClickListener(myOnBtnClickListener); return convertView; } private OnClickListener myOnBtnClickListener = new OnClickListener() { @Override public void onClick(View v) { final int posit = bookListView.getPositionForView((View) v.getParent()); Toast.makeText(getApplicationContext(), Integer.toString(posit), Toast.LENGTH_LONG).show(); } }; </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.
 

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