Hey new in android just create an app in that change the text color after change position of the in list view, when I am changing the position of the ABC at the same time change the new position ABC "Assigning" to "Assigned" text with change Assigned color red. please help me.
private class CurrentEmployeeAdapter extends BaseAdapter {
Context context;
int layoutId;
LayoutInflater liCurrentEmp;
public CurrentEmployeeAdapter(CurrentEmployee currentEmployee, int activity_current_employee) {
this.context=currentEmployee;
this.layoutId=activity_current_employee;
liCurrentEmp=LayoutInflater.from(context);
}
@Override
public int getCount() {
return SalesManNameArrayList.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View v;
if (convertView==null){
convertView=liCurrentEmp.inflate(R.layout.current_employee_items,parent,false);
v=convertView;
}else {
v=convertView;
}
TextView tvEmpName=(TextView)v.findViewById(R.id.tv_salesman_name);
final TextView tvassingwork=(TextView)v.findViewById(R.id.tv_assign_word);
Button btnAssign=(Button)v.findViewById(R.id.btn_assign);
btnAssign.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
tvassingwork.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (assignNo==1) {
tvassingwork.setText("Assigning");
tvassingwork.setTextColor(getResources().getColor(R.color.green));
assignNo=0;
}else {
int i=position+1;
if(i >0) {
String moveName = SalesManNameArrayList.get(position);
SalesManNameArrayList.set(position, SalesManNameArrayList.get(position));
SalesManNameArrayList.remove(position);
SalesManNameArrayList.add(SalesManNameArrayList.size(), moveName);
tvassingwork.setText("Assigned");
tvassingwork.setTag(position-1);
tvassingwork.setTextColor(getResources().getColor(R.color.red));
assignNo=1;
notifyDataSetChanged();
}
}
}
});
tvEmpName.setText(SalesManNameArrayList.get(position));
return convertView;
}
}
Try this
tvassingwork.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
if (assignNo==1) {
tvassingwork.setText("Assigning");
tvassingwork.setTextColor(getResources().getColor(R.color.green));
assignNo=0;
}else {
int i=position+1;
if(i >0) {
String moveName = SalesManNameArrayList.get(position);
SalesManNameArrayList.set(position, SalesManNameArrayList.get(position));
SalesManNameArrayList.remove(position);
SalesManNameArrayList.add(SalesManNameArrayList.size(), moveName);
tvassingwork.setText("Assigned");
tvassingwork.setTag(position-1);
tvassingwork.setTextColor(getResources().getColor(R.color.red));
assignNo=1;
notifyDataSetChanged();
}
}
});
}
});
runOnUIThread() may helps you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.