I have two fragments in an activity and my first fragment is extending ListFragment class and there is one ListView widget whose id is 'list' in its xml layout. I wrote a custom adapter for this List and works fine but I need to click an item to pass some values to another fragment. For itemClick event I guess, I must use onListItemClick() method of ListFragment class.But when I run the app and click an item in list nothing happened.
public class List extends ListFragment {
private Context context;
ListAdapter listAdapter;
OnHeadlineSelectedListener mCallback;
public interface OnHeadlineSelectedListener {
public void onArticleSelected(int position);
}
@Override
public void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
KnlContainer knlModel = new KnlContainer();
listAdapter = new ListAdapter((Activity)context,knlModel);
}
@Override
public void onAttach(Activity activity){
super.onAttach(activity);
context = activity;
//I need to call this instance of interface to comminacation with Activity
try {
mCallback = (OnHeadlineSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// Send the event to the host activity
//for comminacation with activity
mCallback.onArticleSelected(position);
Log.e("STAT","OK");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
LinearLayout rootView = (LinearLayout)inflater.inflate(R.layout.knl_list_fragment, null);
ListView knllrList = (ListView)rootView.findViewById(android.R.id.list);
knllrList.setAdapter(listAdapter);
return rootView;
}
}
I must define clicklistener in adapter ?