Question

I have made a custom ListAdapter,I have binded some textView in that adapter,I want to perform click event of adapter's textview,and passing some value to another activity,I have tried as below,But thing is that i am getting diffrent value than current textView when my ListView is loaded,So i need only the value of the textView which is Clicked.But curently i ma getting the botton most of Displayed ListView in the screen,Please help me for that y code is as below:

adapter.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...........!!!!!
     */


    }
}
Was it helpful?

Solution

You need to remove 2 following things

  1. Remove Static Variable from your localViewholder

  2. at the time of getTag() you are again creating new instance of localViewholder remove it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top