开发者

getting problem with list onItemClick event with android 2.1 update?

list not getting click event when there is only one element in the list.this code works fine with 1.6 and 2.2. only problem is when there is only one row in list.

can anybody tell me开发者_如何学Python i have tried setfocusable and setfocusableintouchmode but didnt get solution.

here is my code for click event. lvTrackData.setOnItemClickListener(new OnItemClickListener() { @SuppressWarnings("static-access") public void onItemClick(AdapterView arg0, View v, int position,long id) {

} }

where lvtrackdata is my listview.this code works fine if the elements are greater than 1.


try this.. it works for both custom Adapter and Arrayadapter
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final List<String> list=new ArrayList<String>();
    list.add("Android");
    ListView listView=(ListView)findViewById(R.id.list);
   // listView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list));
    listView.setAdapter(new MyArrayAdapter(getApplicationContext(), 0,list));
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
        Toast.makeText(getApplicationContext(),list.get(arg2),Toast.LENGTH_SHORT).show();   

        }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜