I have a listview with custom adapter in listfragment and also set onclicklistner for listview. But Onclicklistner does not work.
Here is my code:
p
Put the following code in onViewCreated() method:
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
ListView list = (ListView) view.findViewById(android.R.id.list);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView> parent, View view,
int position, long id) {
Toast t = Toast.makeText(getActivity(), "Message",
Toast.LENGTH_SHORT);
t.show();
}
});
}
The problem may lie in the fact that the view is not constructed yet in onViewCreate(), so it's not advisable to set the listeners there.