Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 客户适配器不工作的Listview侦听器_Android_Listview_Android Listview_Android Adapter - Fatal编程技术网

Android 客户适配器不工作的Listview侦听器

Android 客户适配器不工作的Listview侦听器,android,listview,android-listview,android-adapter,Android,Listview,Android Listview,Android Adapter,我已经多次看到这个问题,我正在使用客户适配器用我的客户布局xml填充我的Listview。我知道点击可能永远不会进入列表视图,我的布局也会阻止它,但在尝试了可能的解决方案后,似乎什么都没有尝试: 尝试: android:genderantfocusability=“blocksDescendants” 用于自定义xml的布局 android:focusableInTouchMode="false" android:clickable="false" android:focusable="fals

我已经多次看到这个问题,我正在使用客户适配器用我的客户布局xml填充我的Listview。我知道点击可能永远不会进入列表视图,我的布局也会阻止它,但在尝试了可能的解决方案后,似乎什么都没有尝试:

尝试: android:genderantfocusability=“blocksDescendants” 用于自定义xml的布局

android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false" 
对于布局中的每个单独元素

还有别的办法吗

编辑

添加listview连接到适配器的位置的代码:

if(!allcontactsstring.isEmpty()){
  adapter = new MyContactListAdapter(getContext(),R.layout.contact_list_view,imageArry);
       listView.setAdapter(adapter);
   }

AdapterView.OnItemClickListener mylistViewClicked = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getContext(),"S"+position,Toast.LENGTH_LONG);
        }
    };
    listView.setOnItemClickListener(mylistViewClicked);

有这么多的监听器并不干净,如果只有一个监听器就好了,但现在它可以工作了。

那么你的点击可以工作了,但它对你的代码不起作用的是你没有看到祝酒词,对吗?您刚刚忘记在
Toast.makeText(getContext(),“S”+位置,Toast.LENGTH\u LONG)
上调用show(),它应该是
Toast.makeText(getContext(),“S”+位置,Toast.LENGTH\u LONG)。show()

享受:p


编辑

好吧,你的点击是有效的,但它对你的代码不起作用的是,你没有看到祝酒词,对吗?您刚刚忘记在
Toast.makeText(getContext(),“S”+位置,Toast.LENGTH\u LONG)
上调用show(),它应该是
Toast.makeText(getContext(),“S”+位置,Toast.LENGTH\u LONG)。show()

享受:p


编辑

我知道点击可能永远不会进入列表视图,而我的布局会阻止它。你的确切意思是什么?请你延长/澄清一下好吗?thanks@jordiCastilla,我有一个带有图像视图和文本视图的线性布局。正是这种布局在我的listview的每个项目中都得到了填充。因此,如果我单击listview,我的单击是否会被listview的侦听器拾取。如果您在
列表视图中添加了一个侦听器,那么是的。@Jordi Castilla,我不确定图像视图或文本视图的单击是否会导致问题,面临类似的问题,但是有了解决方案,它就不起作用了如果你不发布MVCE它很难弄明白…我知道点击可能永远不会进入列表视图,我的布局阻止了它你到底是什么意思?请你延长/澄清一下好吗?thanks@jordiCastilla,我有一个带有图像视图和文本视图的线性布局。正是这种布局在我的listview的每个项目中都得到了填充。因此,如果我单击listview,我的单击是否会被listview的侦听器拾取。如果您在
列表视图中添加了一个侦听器,那么是的。@Jordi Castilla,我不确定图像视图或文本视图的单击是否会导致问题,因为它们面临着类似的问题,但有解决方案,并且它不起作用。如果您不发布MVCE,则很难理解它……很抱歉,这是一个打字错误,使用
Toast.makeText(getContext(),“S”+position,Toast.LENGTH\u LONG).show();
它也不显示任何内容…Mmmmmm…我几乎可以肯定这是因为当您的自定义布局上有可聚焦视图(按钮、复选框、图像按钮等)时,列表视图上的聚焦问题适用(请参阅)是的,甚至我认为我应该担心可聚焦视图,但即使是ImageView也会导致它,我想,我现在不确定这个问题有5个小时了,我只是“复制粘贴”你的代码,但为了简单起见,我使用ArrayAdapter,而不是使用ArrayList。我还删除了布局xml上的所有焦点,它确实有效(请参见编辑)。因此,还有其他原因导致了您的错误。很抱歉,这是一个打字错误,
Toast.makeText(getContext(),“s”+position,Toast.LENGTH_LONG)。show();
它也没有显示任何内容……嗯……我几乎可以肯定这是因为当您有可聚焦视图时,列表视图上的焦点问题适用(按钮、复选框、ImageButton等…)在您的自定义布局上,您没有(看到)完全正确,即使我认为我应该担心聚焦视图,但即使是ImageView也会导致它,我想,我现在不确定这个问题有5个小时了,我只是“复制粘贴”“您的代码没有使用ArrayList,但为了简单起见,我使用ArrayAdapter。我还删除了布局xml上的所有焦点rubish,它确实有效(请参见编辑)。因此,还有其他原因导致了您的错误。
public class MyContactListAdapter extends ArrayAdapter<MySQLiteContact> {

Context context;
int layoutResourceId;
ArrayList<MySQLiteContact> data=new ArrayList<MySQLiteContact>();


public MyContactListAdapter(Context context, int resource, ArrayList<MySQLiteContact> objects) {
    super(context, resource, objects);
    //this.layoutResourceId = layoutResourceId;
    this.layoutResourceId = resource;
    this.context = context;
    this.data = objects;



}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    ImageHolder holder = null;

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);
        //ImageView tmp = (ImageView)row.findViewById(R.id.icon);
        //tmp.clearFocus();
        //tmp.isClickable();

        //TextView tmp1=(TextView)row.findViewById(R.id.Itemname);
        //tmp1.clearFocus();


        holder = new ImageHolder();
        holder.txtTitle = (TextView)row.findViewById(R.id.Itemname);
        holder.imgIcon = (ImageView)row.findViewById(R.id.icon);
        row.setTag(holder);

    }
    else
    {
        holder = (ImageHolder)row.getTag();
    }

    MySQLiteContact picture = data.get(position);
    holder.txtTitle.setText(picture.getsFirstName()+" "+picture.getsLastName());
    byte[] outImage=picture.getBimage();
    ByteArrayInputStream imageStream = new ByteArrayInputStream(outImage);
    Bitmap theImage = BitmapFactory.decodeStream(imageStream);
    theImage=Bitmap.createScaledBitmap(theImage , 100, 100, true);
    theImage= ContactDetailsMain.getRoundedRectBitmap(theImage,100);
    holder.imgIcon.setImageBitmap(theImage);


    return row;



}

static class ImageHolder
{
    ImageView imgIcon;
    TextView txtTitle;
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"   
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants">
<ImageView                                          
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
android:src="@drawable/ic_contact_picture_holo_light"
/>
<TextView
android:id="@+id/Itemname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="@color/black"
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
android:paddingTop="5dp"
/>
</LinearLayout>
if(row == null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        row.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.out.println(position);
            }
        });