0

我有一个扩展列表片段的类,由于某种原因,该片段没有接收到列表项的点击。我已将问题缩小到行项目,但我仍然看不到问题所在。这是我的 XML。有任何想法吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:focusable="true">   
<ImageButton
    android:id="@+id/image_button"
    android:layout_width="120px"
    android:layout_height="120px"
    android:scaleType="fitXY"/>
<TextView
    android:id="@+id/text_view1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge"/>

这是我在自定义适配器中扩展此布局的方法:

public View getView(int position, View convertView, ViewGroup parent){
    LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = vi.inflate(R.layout.list_item, parent, false);
    T t = list.get(position);
    TextView tv1 = (TextView) view.findViewById(R.id.text_view1);
    tv1.setText(t.getName());
    ImageButton image= (ImageButton) view.findViewById(R.id.image_button);
    image.setBackgroundColor(Color.parseColor("blue"));
    return view;
  }
4

1 回答 1

0

我没有在您的父布局中看到 android:focusable="true" 的任何原因,除非您试图解决您的问题:将焦点从列表切换到列表项。从您的布局中删除该元素,它会正常工作。

经过修改的版本 :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:focusable="true">   
    <ImageButton
        android:id="@+id/image_button"
        android:layout_width="120px"
        android:layout_height="120px"
        android:scaleType="fitXY"/>
    <TextView
        android:id="@+id/text_view1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge"/>
于 2013-10-23T07:47:38.230 回答