onItemClick不起作用。是什么原因? 我只想通过点击ListView的项目来获得Second,GreetingActivity
lvData.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "itemClick: position = " + position + ", id = " + id);
String selectedFromList =(String) (lvData.getItemAtPosition(position));
Intent intent = new Intent(getApplicationContext(), GreetingActivity.class);
intent.putExtra("item_name", selectedFromList);
startActivity(intent);
}
});
这是item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.28"
android:textSize="20sp"
android:focusable="false"
android:text="Button" />
</LinearLayout>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="kg.aykut.speak_kyrgyz.MainActivity" >
这是我的listview
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never"/>
答案 0 :(得分:0)
试试这个:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.28"
android:textSize="20sp"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Button" />