BaseAdapterを使用してListFragmentを作成しようとしています。しかし、カスタムアダプタを使用するとonItemClickイベントが機能しません。希望のビューが表示されますが、CustomAdapterでアイテムのクリックが発生しません。
私は次のコードを使用しています
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//following code do not fire on click event
setListAdapter(new TestListAdapter(getActivity(), test)); //test is a Arraylist
//following code perfectly fine
setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, new String[] { "One", "Two", "Three"}));
}
これは私のTestListAdapterです
class TestListAdapter extends BaseAdapter {
private LayoutInflater inflater=null;
private ArrayList<Xyz> tests;
private Context mContext;
TestListAdapter(Context context, ArrayList<Xyz> tests){
//super(context, tests);
mContext=context;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.tests=tests;
}
public int getCount() {
// TODO Auto-generated method stub
return tests.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return tests.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view=convertView;
if(convertView==null)
view = inflater.inflate(R.layout.my_list_row, null);
TextView tvName = (TextView)view.findViewById(R.id.testName); // title
return view;
}
}
私は次の関数をオーバーライドしました、そしてそれは私がそれがArrayAdapterで動作していることを知っている方法です。
public void onListItemClick(ListView l, View v, int position, long id) {
Log.d("XYZ","click.......");
}