2011-12-28 74 views
5

我有一个ListView的内容为假设android在第一行,黑莓在第二行和iPhone在第三行所以现在我想让ListView的整行可点击,但是当我点击上面列表视图行的内容,那么它执行只有点击事件,但我想如果我点击行中的任意地方,然后点击动作要制作列表视图点击performed.My代码如下:在XML如何在列表视图中使全行可点击android

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.listartistspacedetailview); 

    setListAdapter(new ArrayAdapter(this,R.layout.listitem_layout,R.id.barrio, keywordxmlparsing.array_artistname)); 

} 
@Override 
protected void onListItemClick(ListView l, View v, int position, long thisID) 
{ 
    Intent i = new Intent(Artistspacedetailview.this, Loadingimagetab.class); 
    startActivity(i); 
} 

和ListView标签文件是:

<ListView 
    android:clickable="true" 
    android:layout_marginLeft="10dip" 
    android:layout_marginRight="10dip" 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_below="@id/horizontolline" 
    android:cacheColorHint="#00000000" 
    android:drawSelectorOnTop="false" /> 
+4

你的问题还不清楚。点击一个listitem可能应该选择raw(应该捕获它的点击事件)。不清楚你有什么问题! – Hiral 2011-12-28 11:33:01

+0

请发布listitem_layout。 – Ian 2011-12-28 11:39:02

+0

我的意思是,当我点击列表iten在一行然后只列表行是可点击其他明智的点击事件不fire.even我定义android:clickable =“true”,并使列表视图的宽度填充父。 – shyam 2011-12-29 04:28:47

回答

-2

这可能对您有所帮助...

listView.setOnItemClickListener(new OnItemClickListener() { 
@Override 
public void onItemClick(AdapterView<?> list, View view, int position, long id) { 
      //code to be executed. 
    } 

} 
}); 
8

我知道这个问题已经过时了,但当我在寻找这个问题时,它是我在谷歌的第一次打击。

这是我的解决方案。

<ListView 
    android:id="@+id/XXXXXX" 
    android:layout_width="fill_parent" // Changed from wrap content 
    android:layout_height="fill_parent" // Changed from wrap content 
    android:clickable="true" >   // This was suggested in other topics 
</ListView> 
2

这是旧的,但对其他任何人都有帮助。将膨胀布局设置为填充父项并将布局内可以单击的任何其他项设置为false,以使列表项可以获得所有焦点。还要将项目设置为可聚焦false,并且focusableOnTouch也为false。

相关问题