Android 获取OnItemClick item点击 事件中组件的内容

public void onItemClick(AdapterView<?>parent, View view, int position, long id)

// parent是识别是哪个listview;

// view是当前listview的item的view的布局,就是可以用这个view,获取里面的控件的id后操作控件

// position是当前item在listview中适配器里的位置

// id是当前item在listview里的第几行的位置

例如:在ListView中自定义布局里有一个TextView组件,需要取出TextView中的内容可以用如下做法

这个很简单的只要将你写在Adapter的 赋值的控件找到 就可以了
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//collectionContent为自定义布局中TextView的id
TextView textView= (TextView) view.findViewById(R.id.collectionContent);
Toast.makeText(this, textView.getText(), Toast.LENGTH_SHORT).show();
}

猜你喜欢

转载自blog.csdn.net/xieyaofeng/article/details/105839704