我有一個對象的項目列表。我使用for循環創建了按照列表大小的動態按鈕。如何切換數據點擊按鈕?
我正在顯示一些數據時,它的第一個項目的循環。現在/我想在點擊按鈕時切換數據。
按鈕將具有該項目的編號,如果列表中有三個項目,則三個按鈕在那裏命名爲一,二,三。
所以如果我先點擊第一項我要顯示第一項的數據,如果第二項點擊第二項的數據。
我試圖做到這一點,但我無法得到結果。
@Override
public void doPostExecute(List<Payment> list1)
{
list.addAll(list1);
for(final Payment payment : list) {
i++;
Button myButton = new Button(getActivity());
LinearLayoutCompat.LayoutParams lp = new LinearLayoutCompat.LayoutParams(60,30);
linear_buttons.addView(myButton, lp);
myButton.setText(String.valueOf(i));
myButton.setBackgroundResource(R.drawable.edit_button);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (payment.getPaidAmount() != null && !payment.getPaidAmount().equals("null"))
txt_paid.setText("$" + payment.getPaidAmount());
if (payment.getProductStatus() != null && !payment.getProductStatus().equals("null")) {
if (payment.getProductStatus().equals("1")) {
txt_status.setText(getString(R.string.paid));
button_complain.setVisibility(View.VISIBLE);
button_more.setVisibility(View.GONE);
} else if (payment.getProductStatus().equals("0")) {
txt_status.setText(getString(R.string.unPaid));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.GONE);
} else if (payment.getProductStatus().equals("5")) {
txt_status.setText(getString(R.string.processing));
button_complain.setVisibility(View.VISIBLE);
button_more.setVisibility(View.GONE);
} else if (payment.getProductStatus().equals("6")) {
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
txt_status.setText(getString(R.string.releasedStatus));
} else if (payment.getProductStatus().equals("8")) {
txt_status.setText(getString(R.string.disputeStatus));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
} else if (payment.getProductStatus().equals("9")) {
txt_status.setText(getString(R.string.disputeResolvedStatus));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
} else if (payment.getProductStatus().equals("2")) {
txt_status.setText(getString(R.string.completedStatus));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
}
if (payment.getTpAmount() != null && !payment.getTpAmount().equals("null")) {
String amount = String.format(Locale.US, "%.2f", Double.parseDouble(payment.getTpAmount()));
txt_tp_amount.setText("$" + amount);
}
if (payment.getCommission() != null && !payment.getCommission().equals("null")) {
String amount = String.format(Locale.US, "%.2f", Double.parseDouble(payment.getCommission()));
txt_comission.setText("$" + amount);
}
if (payment.getTax() != null && !payment.getTax().equals("null")) {
String amount = String.format(Locale.US, "%.2f", Double.parseDouble(payment.getTax()));
txt_tax.setText("$" + amount);
}
if (payment.getPayeEmail() != null && !payment.getPayeEmail().equals("null")) {
txt_payee_email.setText(payment.getPayeEmail());
}
if (payment.getPayerEmail() != null && !payment.getPayerEmail().equals("null")) {
txt_payer_email.setText(payment.getPayerEmail());
}
if (payment.getPayerName() != null && !payment.getPayerName().equals("null")) {
txt_payer_name.setText(payment.getPayerName());
}
if (payment.getVendorId() != null && !payment.getVendorId().equals("null")) {
txt_vendor_id.setText(payment.getVendorId());
}
}
}
});
if(i==1) {
if (payment.getPaidAmount() != null && !payment.getPaidAmount().equals("null"))
txt_paid.setText("$" + payment.getPaidAmount());
if (payment.getProductStatus() != null && !payment.getProductStatus().equals("null")) {
if (payment.getProductStatus().equals("1")) {
txt_status.setText(getString(R.string.paid));
button_complain.setVisibility(View.VISIBLE);
button_more.setVisibility(View.GONE);
} else if (payment.getProductStatus().equals("0")) {
txt_status.setText(getString(R.string.unPaid));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.GONE);
} else if (payment.getProductStatus().equals("5")) {
txt_status.setText(getString(R.string.processing));
button_complain.setVisibility(View.VISIBLE);
button_more.setVisibility(View.GONE);
} else if (payment.getProductStatus().equals("6")) {
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
txt_status.setText(getString(R.string.releasedStatus));
} else if (payment.getProductStatus().equals("8")) {
txt_status.setText(getString(R.string.disputeStatus));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
} else if (payment.getProductStatus().equals("9")) {
txt_status.setText(getString(R.string.disputeResolvedStatus));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
} else if (payment.getProductStatus().equals("2")) {
txt_status.setText(getString(R.string.completedStatus));
button_complain.setVisibility(View.GONE);
button_more.setVisibility(View.VISIBLE);
}
if (payment.getTpAmount() != null && !payment.getTpAmount().equals("null")) {
String amount = String.format(Locale.US, "%.2f", Double.parseDouble(payment.getTpAmount()));
txt_tp_amount.setText("$" + amount);
}
if (payment.getCommission() != null && !payment.getCommission().equals("null")) {
String amount = String.format(Locale.US, "%.2f", Double.parseDouble(payment.getCommission()));
txt_comission.setText("$" + amount);
}
if (payment.getTax() != null && !payment.getTax().equals("null")) {
String amount = String.format(Locale.US, "%.2f", Double.parseDouble(payment.getTax()));
txt_tax.setText("$" + amount);
}
if (payment.getPayeEmail() != null && !payment.getPayeEmail().equals("null")) {
txt_payee_email.setText(payment.getPayeEmail());
}
if (payment.getPayerEmail() != null && !payment.getPayerEmail().equals("null")) {
txt_payer_email.setText(payment.getPayerEmail());
}
if (payment.getPayerName() != null && !payment.getPayerName().equals("null")) {
txt_payer_name.setText(payment.getPayerName());
}
if (payment.getVendorId() != null && !payment.getVendorId().equals("null")) {
txt_vendor_id.setText(payment.getVendorId());
}
}
}
}
}
我該如何做到這一點?請幫忙..謝謝。
獲取數據如何將此開關是否行得通呢?我不知道數組的大小和將創建多少個按鈕將基於數據,所以如何檢查交換機中的正確對象? – Sid
如何在開關的情況下? – Sid
@Sid你的代碼在問題中發生了什麼,以及你想要做什麼? –