Android的检索列表视图项中单击自定义适配器 [英] Android retrieve listview item clicked in custom adapter
问题描述
我在Android开发新的,和我有一个麻烦既检索位置和项目在的ListView
。
I'm new in Android development, and i have a trouble retrieving both position and item clicked in ListView
.
我做了一个自定义适配器为我的的ListView
三的TextView
。
I made a custom adapter for my ListView
with three TextView
.
我实现了:
@覆盖
公共无效onItemClick(适配器视图为arg0,ARG1观,诠释ARG2,长ARG3){
@Override public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
我可以检索没有问题,我点击什么位置,却找不到什么的TextView
我的行中点击了一个解决方案。
I can retrieve without problem what position I clicked, but can't find a solution for what TextView
I clicked in the row.
ARG2和参数3始终是相同的值,任何想法热化解?
arg2 and arg3 are always the same value, any idea hot to resolve?
感谢。
推荐答案
在您的列表适配器放在 onClickListener
上的TextView,你就会得到它的触摸值
我把只与code在这里
试试这个,它为我工作
In your list adapter put onClickListener
on textview and you'll get its value on touch
I am putting only related code here
try this, it worked for me
viewHolder.userName = (TextView) convertView.findViewById(R.id.username);
viewHolder.userName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TextView text=(TextView)v;
if(text!=null){
System.out.println("\nUsername :"+text.getText().toString());
}
});
希望它能帮助,干杯!...
Hope it helps,Cheers!...
这篇关于Android的检索列表视图项中单击自定义适配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!