开发者

ListView is not responding to clicks

开发者 https://www.devze.com 2023-04-09 18:35 出处:网络
whats wrong with this class? the clicks in the listview arent registered, i tried to do a log, but it doesnt go into the setItemOnClickListener

whats wrong with this class? the clicks in the listview arent registered, i tried to do a log, but it doesnt go into the setItemOnClickListener

public class Chosen extends Activity{
SimpleCursorAdapter adapter;
String[] getResult;
Cursor c;
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chosen);
    Intent i=getIntent();
    Bundle extras=i.getExtras();
    final TextView t=(TextView) findViewById(R.id.tv1);
    int num=extras.getInt("category");
    ArrayList al=new ArrayList<String>();
    switch(num)
    {
    case 0:c=Splash.db.getSocial(Login.uname);break;
    case 1:c=Splash.db.getMail(Login.uname);break;
    case 2:c=Splash.db.getBank(Login.uname);break;
    case 3:c=Splash.db.getMisc(Login.uname);break;
    }
    if(c.moveToFirst())
    {
        do
        {
            al.add(c.getString(1));
        }while(c.moveToNext());
    }

    getResult=new String[al.size()];
    al.toArray(getResult);
    ListView lv=(ListView) findViewById(R.id.list);
    lv.setClickable(true);
    ArrayAdapter ad=new ArrayAdapte开发者_JS百科r(this,R.layout.chosenitemlist,R.id.client,getResult);
    lv.setAdapter(ad);

    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                long id) {
            // TODO Auto-generated method stub
            Log.w("akash", "in list item click");
            t.setText("clicked");
            Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_LONG).show();
        }
    });
}

}


Interesting. First, try on several scenarios I've checked myself: http://xjaphx.wordpress.com/2011/07/14/listview-doesnt-respond-to-onitemclicklistener/

If problem still, you might want to share your source code, I'd like to analyze if it's a new scenario. In case you cant' share full source, then try to create a new project and put all necessary code, and share :)


One more scenario I have found (not listed by xjaphx): my row layout has had a textview and two images, and some of them has had "clickable = true". Setting it to "false" fixed the problem.

0

精彩评论

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

关注公众号