在我的程序使用列表和适配器中。item_list.xml中有textview(cod,time,...)和图片(editicon)。现在,我想当我单击pictur时,鳕鱼textview中的内容是什么,其他textview中的内容又发送另一个活动。我该如何发送textview中的所有内容。我只是了解了使用putextra发送textvie的内容。谢谢亲爱的朋友
公共类ContactAdapter扩展了ArrayAdapter { 私人列表联系人;
public ContactAdapter(Context context, List< MyContact> contacts) {
super(context,R.layout.item_list,contacts);
this.contacts=contacts;
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MyContact contact = contacts.get(position);
ViewHolder holder;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_list, parent, false);
holder = new ViewHolder();
holder.companyname = (TextView) convertView.findViewById(R.id.companyname);
holder.cod = (TextView) convertView.findViewById(R.id.cod);
holder.bigan = (TextView) convertView.findViewById(R.id.bign);
holder.stop = (TextView) convertView.findViewById(R.id.stop);
holder.time = (TextView) convertView.findViewById(R.id.time);
holder.date = (TextView) convertView.findViewById(R.id.date);
holder.price = (TextView) convertView.findViewById(R.id.price);
holder.editicon = (ImageView) convertView.findViewById(R.id.imageView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.fill(contact);
return convertView;
}
private class ViewHolder implements View.OnClickListener {
public TextView companyname;
public TextView cod;
public TextView bigan;
public TextView stop;
public TextView date;
public TextView time;
public TextView price;
public ImageView editicon;
public void fill(MyContact contact) {
companyname.setText(contact.getCompany());
cod.setText(contact.getCod());
time.setText(contact.getTime());
date.setText(contact.getDate());
bigan.setText(contact.getBigan());
stop.setText(contact.getStop());
price.setText(contact.getPrice());
editicon.setTag(contact.getCod());
// editicon.setTag(contact.getBigan());
editicon.setOnClickListener(this);
}
@Override
public void onClick(View v) {
String codearash = (String) v.getTag();
Intent intent12 = new Intent(getContext(), Cod.class);
intent12.putExtra("keycod", codearash);
getContext().startActivity(intent12);
}
}
}
答案 0 :(得分:0)
您似乎正在做的是在您点击的视图中寻找ListView
。这将失败。
您需要在editicon
类的onClick
实现中激发意图。
ViewHolder