ListFragment有图像和textview,无法点击每个项目

时间:2015-12-24 21:08:00

标签: android android-listfragment

我正在尝试在我的列表片段上放置一个图像和一些textview,这是我可以做的事情但是当我执行程序时我无法选择任何项目,有人可以告诉我如何解决这个问题,我我会粘贴你的代码:

包含图片和textviews的xml:

div

arrayadapter类:

mylist

我有列表的片段:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">


    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imagen"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/nombreUsuario"
        android:layout_alignParentTop="true"
        android:layout_toEndOf="@+id/imagen" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/calle"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/fechaPedido"
        android:layout_alignBottom="@+id/imagen"
        android:layout_toEndOf="@+id/imagen" />

该片段的xml:

   public class AdaptadorDatosListviewChofer extends ArrayAdapter<ParseObject>{
        private Context mContexto;
        private List<ParseObject> mPedido;

    public AdaptadorDatosListviewChofer(Context contexto, List<ParseObject> pedido) {
        super(contexto, R.layout.item_lista_chofer,pedido);
        mContexto=contexto;
        mPedido=pedido;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if(convertView == null){
            convertView = LayoutInflater.from(mContexto).inflate(R.layout.item_lista_chofer,null);
            holder = new ViewHolder();
            holder.imagen = (ImageView) convertView.findViewById(R.id.imagen);
            holder.nombre = (TextView) convertView.findViewById(R.id.nombreUsuario);
            holder.domicilio= (TextView) convertView.findViewById(R.id.calle);
            holder.fechaPedido=(TextView) convertView.findViewById(R.id.fechaPedido);

            holder.imagen.setImageResource(R.mipmap.ic_launcher);
            holder.nombre.setText("prueba");


        }




        return convertView;
    }

    private static class ViewHolder{
            ImageView imagen;
            TextView  nombre;
            TextView  domicilio;
            TextView  fechaPedido;

    }
}

1 个答案:

答案 0 :(得分:-1)

问题是由ImageButton尝试添加到您的XML文件引起的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:weightSum="1"
   android:descendantFocusability="blocksDescendants" > //Defines the relationship between the ViewGroup and its descendants
   <ImageButton
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/imagen"
       android:layout_alignParentTop="true"
       android:layout_alignParentStart="true"
       android:src="@mipmap/ic_launcher"
       android:focusable="false" // set the focusability to false
       android:focusableInTouchMode="false" // also here /> ...