我的listView有问题。我使用自定义适配器类来显示列表项目。 我的问题是,当我点击位置1上的列表视图按钮时,位置10上的按钮也被点击。我如何克服这个问题?当我们在位置1点击ListView按钮时,第10个位置的按钮也被点击
这里是我的代码:
public static class Clockin_Group extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
private Context context;
public Clockin_Group(Context context) {
mInflater = LayoutInflater.from(context);
this.context = context;
}
@Override
public int getCount() {
if(employeeList==null){
return 0;
}
else{
return employeeList.length;
}
}
@Override
public Object getItem(int position) {
return employeeList[position];
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null){
convertView = mInflater.inflate(R.layout.group_clkin_row, null);
holder = new ViewHolder();
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
holder.tv = (TextView) convertView.findViewById(R.id.group_name);
holder.tv.setText(employeeList[position]);
holder.tv1 = (TextView) convertView.findViewById(R.id.loc_id_tv);
holder.tv1.setText("["+empNo_Array[position]+"]");
holder.check = (ImageView) convertView.findViewById(R.id.checkmark);
holder.check.setVisibility(View.GONE);
holder.time = (TextView) convertView.findViewById(R.id.time);
holder.time.setText("Last Clock " +punchType_array[position]+" "+"at"+" "+punchTime_array[position]);
holder.clkin_tv = (TextView) convertView.findViewById(R.id.tv_clockin);
holder.clkin_tv.setVisibility(View.GONE);
holder.button = (Button) convertView.findViewById(R.id.group_button);
holder.button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
employee_id = Integer.parseInt(emp_idList[position]);
emp_selected = employeeList[position];
System.out.println("selected Emp.."+emp_selected);
boolean Status = false;
String type = "In";
SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, yyyy HH:mm:ss");
Date date=new Date();
String s=sdf.format(date);
System.out.println("GMT: "+s);
try {
Status = sendDetails(corpId, user_name, password,employee_id,location_id_str, task_id_str, "0", type);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
if(Status){
holder.button.setVisibility(View.INVISIBLE);
holder.clkin_tv.setVisibility(View.VISIBLE);
holder.time.setTextColor(Color.parseColor("#088A08"));
holder.check.setVisibility(View.VISIBLE);
holder.time.setText("Last Clock IN at "+sdf.format(new Date()).toString());
System.out.println("Status..");
}
else{
Toast.makeText(context, "Clock In Failed", Toast.LENGTH_SHORT).show();
holder.button.setVisibility(View.VISIBLE);
holder.clkin_tv.setVisibility(View.INVISIBLE);
}
}
});
/*convertView.setOnClickListener(new OnClickListener() {
//private int pos = position;
@Override
public void onClick(View v) {
//Toast.makeText(context, "Click-" + String.valueOf(pos), Toast.LENGTH_SHORT).show();
}
});*/
convertView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(context, employeeList[position]+"["+empNo_Array[position]+"]", Toast.LENGTH_SHORT).show();
return false;
}
});
// convertView.setTag(holder);
return convertView;
}
http://stackoverflow.com/questions/8162835/button-events-in-listview – RobinHood 2012-07-27 06:39:56
你是如何解决这个问题的?标签? – Sunkas 2013-03-20 08:57:38
无法关注您的代码,电视,tv1,clkin_tv缩写使其无法跟随。 – Siddharth 2014-01-17 08:43:31