ListView 不响应点击
这门课有什么问题吗?列表视图中的点击未注册,我尝试记录日志,但它没有进入 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 ArrayAdapter(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();
}
});
}
}
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 ArrayAdapter(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();
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的。
首先,尝试我自己检查过的几个场景: http://xjaphx.wordpress.com/2011/07/14/listview-doesnt-respond-to-onitemclicklistener/
如果问题仍然存在,您可能需要分享一下你的源代码,我想分析一下这是否是一个新的场景。如果您无法共享完整源代码,请尝试创建一个新项目并放置所有必要的代码,然后共享:)
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 :)
我发现的另一种情况(xjaphx 未列出):我的行布局有一个
textview
和两个图像,其中一些有“clickable = true
”。将其设置为“false
”解决了该问题。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.