适配器

时间:2018-03-13 05:47:10

标签: android onitemclicklistener

根据spinner,我在一个标签内有三个listview。微调器有3个选项“ALL”,“PAYMENTS”和“EXPENSES”。实际上有两个列表视图,即;付款和费用。微调器中的“全部”选项将显示付款和费用的组合清单。这两个列表视图具有单个可点击项目,如屏幕截图所示。(SP125-PAYMENTS,OE300-EXPENSE)。如果我点击付款清单的单个项目(例如:SP125),它将转到paymentdetails活动,如果我点击单个费用清单的项目(OE300)将去costdetail活动。如何设置onclick listner,它将同时适用于列表视图?即使从单独的列表(“PAYMENT”或“EXPENSE”)中单击,“ALL”中项目的点击也应相同。?

adapter = new CustomAdapter(getContext(), invoiceListData, Common.PREVIOUSPAYMENTS);
invoiceList.setAdapter(adapter);
(rootView.findViewById(R.id.list_card)).setVisibility(View.VISIBLE);


final ArrayList<String[]>PaymentListData = new ArrayList<>();
final ArrayList<String[]>ExpenseListData = new ArrayList<>();
for (int i = 0; i < invoiceListData.size(); i++) {
    if (invoiceListData.get(i)[6].equals("Payment")) {

        PaymentListData.add(invoiceListData.get(i));

        invoiceList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent approvalDetailsIntent = new Intent(getContext(), ApprovalDetails.class);
                approvalDetailsIntent.putExtra(Common.APPROVALID, common.dataArrayList.get(position)[0]);
                approvalDetailsIntent.putExtra(Common.ENTRYNO, common.dataArrayList.get(position)[1]);
                startActivity(approvalDetailsIntent);
            }
        });

    } else if (invoiceListData.get(i)[6].equals("Expense")) {

        ExpenseListData.add(invoiceListData.get(i));


        invoiceList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent approvalDetailsIntent = new Intent(getContext(), ApprovalExpenseDetails.class);
                approvalDetailsIntent.putExtra(Common.APPROVALID, common.dataArrayList.get(position)[0]);
                approvalDetailsIntent.putExtra(Common.REFNO, common.dataArrayList.get(position)[1]);
                startActivity(approvalDetailsIntent);
            }
        });
    }
}

Padapter = new CustomAdapter(getContext(), PaymentListData, Common.PREVIOUSPAYMENTS); //Global variable
invoiceList.setAdapter(Padapter);
(rootView.findViewById(R.id.list_card)).setVisibility(View.VISIBLE);


Eadapter = new CustomAdapter(getContext(), ExpenseListData, Common.PREVIOUSPAYMENTS);
invoiceList.setAdapter(adapter);
(rootView.findViewById(R.id.list_card)).setVisibility(View.VISIBLE);

截图:

enter image description here

2 个答案:

答案 0 :(得分:0)

如果您正在使用onClickListener,请在onBindViewHolder中设置RecyclerView;如果您正在使用getView,请在ListView设置CustomAdapter ,在Payment课程内。

为此,您需要有办法区分所点击的项目是Expense还是{{1}},然后您可以相应地开始新的活动。

答案 1 :(得分:0)

尝试在适配器中使用 OnClickListener ,而不是使用for循环来获取主活动中的所有值,并从适配器传递值。

{{1}}