我在片段中创建了一个ListView,并使用onStart()方法中名为Workout的类的数据填充它。我设置了一个适配器,列表显示正常。我想现在能够获取用户单击但不能实现onItemClicked()方法的特定行的值。有谁知道我怎么能得到这个价值?谢谢。
setImage()
答案 0 :(得分:1)
使用此:
workoutList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// the 'position' argument is the position you are looking for
}
});
修改强>
我注意到你没有初始化workoutList
listView。您应该在 OnCreateView 方法中执行此操作:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_workout_list, container, false);
workoutList = (ListView) view.findViewById(R.id.workoutListView); // assuming that your listView's id is "@+id/workoutListView"
return view;
}