-3
我已经尝试过使用可点击和可调焦但没有任何东西似乎允许列表项可点击。让列表可点击
xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/add_recipe_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/recipe_activity_add"
android:background="@color/colorPrimary"
android:textColor="#fff"/>
<ListView
android:id="@+id/recipe_list"
android:layout_width="match_parent"
android:focusable="false"
android:clickable="true"
android:layout_height="match_parent" />
Java代码
recipeListView = (ListView)findViewById(R.id.recipe_list);
//make viewRecipe Work
recipeListView.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("MainActivity", "ListView item clicked.");
}
});
默认情况下,列表项可点击。请参阅[本示例应用程序](https://github.com/commonsguy/cw-omnibus/tree/master/Selection/List)。 – CommonsWare
@CommonsWare它不适合我 –
尝试我链接到的示例项目。如果示例项目在您的测试环境中运行,那么您可以确定与您的项目相比您的项目有什么不同。如果示例项目在测试环境中不起作用,那么测试环境存在一些问题。 – CommonsWare