我正在使用Android-Studio。我要分配一个应用程序,该应用程序具有一个Contacts列表,一个进入ListView的每个项目的Layout以及对每个项目中存在的按钮进行操作(setOnClickListener)。
到目前为止,我已经提出了一种具有“调用”,“修改”和“删除”按钮的布局。我关心的是如何从列表项中获取信息,然后将其发送到联系人的“创建/修改”表单。
我检查了几本教程,这些都是我的代码的基础。
public class UserCustomListPrivAdapter extends ArrayAdapter<ContactPriv> {
private Context context;
int layoutRessourceIdentity;
private ArrayList<ContactPriv> data;
public UserCustomListPrivAdapter(Context contexte, int layoutResourceId,ArrayList<ContactPriv> info) {
super(contexte, layoutResourceId, info);
this.context = contexte;
this.layoutRessourceIdentity = layoutResourceId;
this.data = info;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ContactPrivHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutRessourceIdentity, parent, false);
holder = new ContactPrivHolder();
holder.textNom = (TextView) row.findViewById(R.id.listItemTextNomContactPriv);
holder.textTel = (TextView) row.findViewById(R.id.listItemTextContactPrivPhone);
holder.btnTel = (Button) row.findViewById(R.id.btnCall);
holder.btnDelete = (Button) row.findViewById(R.id.btnDelete);
holder.btnModif = (Button) row.findViewById(R.id.btnInfo);
row.setTag(holder);
} else {
holder = (ContactPrivHolder) row.getTag();
}
final ContactPriv user = data.get(position);
holder.textNom.setText(user.getName());
holder.textTel.setText(user.getPhone());
holder.btnTel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_DIAL);// (Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + user.getPhone()));
context.startActivity(callIntent);
}
});
holder.btnModif.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Intent intent = new Intent(v.getContext(),ContactPrivActivity.class);
Intent intent = new Intent();
//Bundle a = new Bundle();
/* intent.putExtra("name","info");
intent.putExtra("uniqueid","info");
intent.putExtra("info","info");
intent.putExtra("name", user.getName());
intent.putExtra("phone",user.getPhone());
intent.putExtra("email",user.getEmail());
intent.putExtra("adresse",user.getAdresse());
*/
context.startActivity(intent);
}
});
holder.btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),ContactPrivActivity.class);
}
});
return row;
}
static class ContactPrivHolder {
TextView textNom;
TextView textTel;
Button btnTel;
Button btnDelete;
Button btnModif;
}
}