gpt4 book ai didi

android - customAdapter 的 textView 值在 android 中执行 clickEvent 时发生变化

转载 作者:行者123 更新时间:2023-11-29 21:09:24 26 4
gpt4 key购买 nike

我做了一个自定义的 ListAdapter,我在那个适配器中绑定(bind)了一些 textView,我想执行适配器的 textview 的点击事件,并将一些值传递给另一个 Activity ,我试过如下,但事情是我得到当我的 ListView 被加载时,与当前 textView 不同的值,所以我只需要被点击的 textView 的值。但目前我在屏幕上获得了大部分显示的 ListView 的按钮,请帮助我,因为 y 代码如下:

适配器.java

public class OrderAdapter extends BaseAdapter {
public ArrayList<HashMap<String, String>> orderArray;
private Context mContext;
String statusCode, status, orderId;
Intent i;

public OrderAdapter(Context paramContext, ArrayList<HashMap<String, String>> productList) {
this.mContext = paramContext;
this.orderArray = productList;
}

public int getCount() {
return this.orderArray.size();
}

public Object getItem(int paramInt) {
return Integer.valueOf(paramInt);
}

public long getItemId(int paramInt) {
return paramInt;
}

@SuppressWarnings("static-access")
public View getView(int paramInt, View paramView, ViewGroup paramViewGroup) {
LayoutInflater localLayoutInflater = (LayoutInflater) this.mContext.getSystemService("layout_inflater");
Viewholder localViewholder = null;
if (paramView == null) {
paramView = localLayoutInflater.inflate(R.layout.raw_order, paramViewGroup, false);
localViewholder = new Viewholder();

localViewholder.orderNo = ((TextView) paramView.findViewById(R.id.tv_order_no));
localViewholder.date = ((TextView) paramView.findViewById(R.id.tv_date));
localViewholder.status = ((TextView) paramView.findViewById(R.id.tv_stats));
localViewholder.proName = ((TextView) paramView.findViewById(R.id.tv_proname));
localViewholder.amount = ((TextView) paramView.findViewById(R.id.tv_amt));
localViewholder.link = ((TextView) paramView.findViewById(R.id.tv_link));

paramView.setTag(localViewholder);

} else {
localViewholder = new Viewholder();
localViewholder = (Viewholder) paramView.getTag();
}
System.out.println("::::::::::::::array indexes::::::::::::" + orderArray.get(paramInt));
System.out.println(":::::::::::::::;;status::::::::::::::::::::;;" + orderArray.get(paramInt).get(Const.TAG_ORDER_STATUS_ID));
statusCode = orderArray.get(paramInt).get(Const.TAG_ORDER_STATUS_ID);
getStatus(statusCode);
orderId = orderArray.get(paramInt).get(Const.TAG_ORDER_ID);
localViewholder.orderNo.setText("Order no.:" + orderId);

localViewholder.date.setText(orderArray.get(paramInt).get(Const.TAG_DATE_ADDED));
localViewholder.status.setText(status);
localViewholder.proName.setText(orderArray.get(paramInt).get(Const.TAG_PRODUCT_NAME));
localViewholder.amount.setText(orderArray.get(paramInt).get(Const.TAG_TOTAL));
if (statusCode.equals("1") || statusCode.equals("2") || statusCode.equals("7") || statusCode.equals("11")) {
localViewholder.link.setVisibility(View.VISIBLE);
localViewholder.link.setText("Review and pay");
System.out.println(":::::::::::::::inside IF::::::::::::::::::;" + orderId);
} else {
System.out.println(":::::::::::::::inside else::::::::::::::::::;" + orderId);
localViewholder.link.setVisibility(View.INVISIBLE);
}
localViewholder.link.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(mContext, OrderWebViewActivity.class);
i.putExtra(Const.TAG_ORDER_ID, orderId);
mContext.startActivity(i);
}
});

return paramView;

}

static class Viewholder {

TextView orderNo;
TextView date;
TextView status;
TextView proName;
TextView amount;
TextView link;

}

/*
* status based Links...........!!!!!
*/


}
}

最佳答案

您需要删除以下 2 个内容

  1. 从您的 localViewholder

    中移除静态变量
  2. getTag() 时,您再次创建 localViewholder 的新实例,将其删除。

关于android - customAdapter 的 textView 值在 android 中执行 clickEvent 时发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23442330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com