0
我有列表數據,然後我希望當我點擊一個項目時它會顯示細節,但我不知道如何將數據傳遞給細節活動。獲取詳細信息數據從Android工作室上的適配器
那麼,如何做到這一點?我已經嘗試了堆棧溢出的可用答案的很多方法,但它們都不起作用,或者與我的問題沒有關係。
所以,請幫助做到這一點。
這裏我的適配器腳本:
public class VoucherAdapter extends ArrayAdapter<Voucher> {
List<Voucher> mVoucherList;
LayoutInflater vi;
int Resource;
VoucherAdapter.ViewHolder holder;
private Context context;
public VoucherAdapter(Context context, int resource, List<Voucher> objects) {
super(context, resource, objects);
vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resource = resource;
mVoucherList = objects;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// convert view = design
View v = convertView;
if (v == null) {
holder = new VoucherAdapter.ViewHolder();
v = vi.inflate(R.layout.list_voucher, parent, false);
holder.kode = (TextView) v.findViewById(R.id.txtkode);
holder.status = (TextView) v.findViewById(R.id.txt_stat);
holder.expiredDate = (TextView) v.findViewById(R.id.txt_tgl_exp);
holder.list = (RelativeLayout) v.findViewById(R.id.itemListVoucher);
v.setTag(holder);
} else {
holder = (VoucherAdapter.ViewHolder) v.getTag();
}
holder.kode.setText(mVoucherList.get(position).getSerialNumber());
holder.status.setText(mVoucherList.get(position).getStatus());
DateFormat df = new SimpleDateFormat("MMM dd yyyy HH:mma");
String reportDate = df.format(mVoucherList.get(position).getExpiryDate());
holder.expiredDate.setText(reportDate);
holder.list.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent detailIntent = new Intent(getContext(), VoucherDetailAktif.class);
context.startActivity(detailIntent);
//how to pass the data to detail activity?
}
});
return v;
}
static class ViewHolder {
public TextView kode;
public TextView expiredDate;
public TextView status;
public RelativeLayout list;
}
}
謝謝
拼寫錯誤,格式和大小 – user7294900