在我的应用程序,我有一个列表视图。列表视图中的每一项包含一个可点击的主体(图像和一些文本)和其他3 textViews它们是可以点击的。
In my application i have a listView. each item of the list view contains a clickable main body(image and some text) and 3 other textViews which are clickable.
当我点击它显示了项目中所示的各区域的地图的项目,这工作得很好,因为我使用onItemClick在我的活动列表视图。
when i click on the item it shows the map of the respective area shown on the item, this works fine because i am using onItemClick on the listview in my activity.
但是,当我要实现的onClick上标记为红色图像中的其他3个TextViews我必须实现的onClick在适配器类的getView方法。
But when i want to implement the onClick on the 3 other TextViews marked red in the image i have to implement the onClick in the getView method of the adapter class.
下面问题来了:
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
ViewHolder holder = new ViewHolder();
p = values.get(position);
String date = new java.text.SimpleDateFormat("dd/MM/yy")
.format(new java.util.Date(p.timeStamp));
if (vi == null) {
vi = inflater.inflate(R.layout.feed_items, null);
holder.text = (TextView) vi.findViewById(R.id.label);
holder.image = (ImageView) vi.findViewById(R.id.logo);
holder.thankLabel = (TextView) vi.findViewById(R.id.thankLabel);
holder.iwantLabel = (TextView) vi.findViewById(R.id.iWantLabel);
holder.detailsLabel = (TextView) vi
.findViewById(R.id.detailsLabel);
holder.thankLabel
.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
}
});
holder.iwantLabel
.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(activity,
IWantActivity.class);
intent.putExtra("productDetails", p.productName
+ "^" + p.reportedPrice);
activity.startActivity(intent);
}
});
holder.detailsLabel
.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
}
});
}
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
return vi;
}
在我的活动时,我想它的项目被点击,我可以使用位置参数的参考,但如果getView的参数位置给新创建的项目,但没有项目的iWant我点击。如何解决这个问题?
in my activity when i want the reference of which item is clicked i can use the position parameter, but in case of getView the parameter position gives the newly created item but not the item's iWant i clicked. how to solve this??
您可以把标签上的标签,并把它作为上下文单击处理程序。
You can put tags on the labels, and use it as the context for the click handler.