Note that there are some explanatory texts on larger screens.

plurals
  1. POButton in a customized listView is not working properly?
    text
    copied!<p>In my application I'm using customized listView with <strong>Text view</strong> and <strong>Button</strong> to change the button image. After I click the button in 1st position, the image of the button changed but when I scroll down the listView, the image set changed to some other position.</p> <pre><code> public class CustomListViewAdapter_ringtone extends BaseAdapter { ArrayList&lt;HashMap&lt;String, String&gt;&gt; list; Activity activity; public CustomListViewAdapter_ringtone(Activity activity,ArrayList&lt;HashMap&lt;String, String&gt;&gt; list) { super(); this.activity = activity; this.list = list; } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } class ViewHolder { Button play; TextView tarck_name,singer; } @Override public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub final ViewHolder holder; LayoutInflater inflater = activity.getLayoutInflater(); if (convertView == null) { convertView = inflater.inflate(R.layout.test, null); holder = new ViewHolder(); holder.tarck_name = (TextView)convertView.findViewById(R.id.track_name); holder.singer = (TextView)convertView.findViewById(R.id.singer); holder.play = (Button)convertView.findViewById(R.id.play_pause_btn); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } HashMap&lt;String, String&gt; map = list.get(position); holder.tarck_name.setText(map.get("track_name")); holder.singer.setText(map.get("sing")); holder.play.setTag(position); holder.play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub holder.play.setBackgroundResource(R.drawable.pausebtn); //here am set the background for the button but when i scroll down the image changed to some other positon } }); return convertView; } } </code></pre>
 

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