我创建了自定义列表视图,在一个列表中有 2 个图像(左、右)和一个文本,当用户单击 image1 时,将调用 activity1 并且用户单击 image2,将调用 activity2 并且当用户单击文本时activity3 将被调用对应于该位置。谁能告诉我我该怎么做?
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
ViewHolder holder;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(row, null);
holder = new ViewHolder();
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
if ((items == null) || ((position + 1) > items.size()))
return view;
objBean = items.get(position);
ImageView img = (ImageView)convertView.findViewById(R.id.contact_photo);
img.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String phoneNumber = objBean.getPhoneNo();
Intent intent = new Intent(Intent.ACTION_CALL, Uri
.parse(phoneNumber));
con.startActivity(intent);
}
});
holder.tvname = (TextView) view.findViewById(R.id.tvname);
holder.tvPhoneNo = (TextView) view.findViewById(R.id.tvphone);
if (holder.tvname != null && null != objBean.getName()
&& objBean.getName().trim().length() > 0) {
holder.tvname.setText(Html.fromHtml(objBean.getName()));
}
if (holder.tvPhoneNo != null && null != objBean.getPhoneNo()
&& objBean.getPhoneNo().trim().length() > 0) {
holder.tvPhoneNo.setText(Html.fromHtml(objBean.getPhoneNo()));
}
return view;
}
public class ViewHolder {
public TextView tvname, tvPhoneNo;
}