我正在使用import android.support.v4.app.ListFragment
创建一个 ListFragment。在片段本身内部——不是父活动——我想实现该onItemClick
方法。有人可以提供一个简单的例子来说明这可能是如何工作的吗?
public class MyListFragment extends ListFragment {
Spannable[] stuff = {};//to be filled
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ArrayAdapter<Spannable> adapter = new ArrayAdapter<Spannable>(inflater.getContext(), android.R.layout.simple_list_item_1, stuff);
setListAdapter(adapter);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//this is red underlined by eclipse
}
}