My aim is to push the list item to the end of the list when the check box is enabled. My list item is an object "Task".
ListView lv=this.getListView();
int size=lv.getCount();
Myarrayadapter adapter = new Myarrayadapter(this,getTasks());
lv.setAdapter(adapter);
lv.invalidateViews();
private List<Task> getTasks() {
List<Task> list = new ArrayList<Task>();
for(int k=0;k<taskname.length;k++)//taskname is an array of tasknames
{
list.add(new Task(taskname[k],status[k]));
return list;
}
Myarrayadapter class is shown below.my aim is to check whether checkbox is enabled.If yes, make some changes(text Colour and button text) and move this changed view to the last position.
public class Myarrayadapter extends ArrayAdapter<Task> {
private final Activity context;
private final List<Task> list;
public Myarrayadapter(Activity context, List<Task> list) {
super(context, R.layout.list_item, list);
this.context = context;
this.list=list;
}
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_item, null, true);
final TextView text = (TextView) rowView.findViewById(R.id.label);
CheckBox checkbox = (CheckBox) rowView.findViewById(R.id.cb);
final Button btnChild = (Button) rowView.findViewById(R.id.directions);
text.setText(list.get(position).getName());
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked)
{
text.setTextColor(Color.parseColor("#468765"));
btnChild.setText("Revert");
Task taskItem= list.get(position);
list.remove(position);
list.add(taskItem);
}
}});
return rowView;
}
Its not moving the exact listitem I wanted.
Thanks in Advance!!!!