大家好,晚上好
i am trying to create custom list view where in the right side i am adding one button initially i ser the text of button to "ADD", now when i click on that button first time text should change to Remove, now my problem is when i click on Button with ADD text, it set Remove text on diff. positions, like if i click on position 1 then it set Remove text to 6th or 7 and 12th like this,
please help me on this any help is appreciated. my code is here
// TODO Auto-generated method stub
// View row = null;
if (convertView == null) {
// if(row==null)
convertView = mInflater.inflate(R.layout.apps_list, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.appName = (TextView) convertView.findViewById(R.id.app_name);
holder.addRemove = (Button) convertView.findViewById(R.id.add_or_remove);
holder.cb = (CheckBox)convertView.findViewById(R.id.cb);
convertView.setTag(holder);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
prefsEditor = myPrefs.edit();
holder.appName.setText(optionalAppsArray.get(position));
String addOrRemove = holder.addRemove.getText().toString();
int pos = position;
holder.addRemove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
if(!bool){
holder.addRemove.setText("Add");
bool = true;
}else {
holder.addRemove.setText("remove");
bool = false;
}
} catch (Exception e) {
// TODO: handle exception
}
}
});
return convertView;
}