我不能点击Android的ListView的? [英] I can't click the ListView in android?

查看:153
本文介绍了我不能点击Android的ListView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用联系人同步的应用程序。我列出有照片,姓名和号码下面的联系方式。我成功地列出所有这些事情在一个自定义的的ListView ,但我不能点击的ListView 。它看起来像被锁定,无法点击。

I made an app using contact sync. I list the following contact info with photo, name and number. I successfully list all those things in a custom ListView, but I can't click the ListView. It looks like locked, Unable to click it.

不过,我犯了一个同样的程序到另一个活动。使用自定义的的ListView ,但我可以点击这个观点并能正常工作。

But I made a same procedure to another activity. Using custom ListView but I can click this view and it works fine.

这是什么问题?这里是我的示例代码:

What is the problem? here is my sample coding:

    ListView settingsList = (ListView) findViewById(R.id.manage_track_listView);
    ArrayList<ContactList> MySettingsList = new ArrayList<ContactList>();

    ContactList setting1 = new ContactList("contact name 1", "Number 1", null);
    ContactList setting2 = new ContactList("contact name 2", "Number 2", null);
    ContactList setting3 = new ContactList("contact name 3", "Number 3", null);

    MySettingsList.add(setting1);
    MySettingsList.add(setting2);
    MySettingsList.add(setting3);

    ContactList list[] = new ContactList[MySettingsList.size()];

    for(int i=0;i<MySettingsList.size();i++) {

        ContactList mySettings = MySettingsList.get(i);
        list[i] = new ContactList(mySettings.getName(), mySettings.getNumber(), mySettings.getImageIcon());
    }

    ContactListAdapter adapter = new ContactListAdapter(this, R.layout.manage_track_list_custom_view, list);
    settingsList.setAdapter(adapter);
    System.out.println("before listener");
    settingsList.setOnItemClickListener(new OnItemClickListener() {

        @Override


        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            // TODO Auto-generated method stub

            System.out.println("Clicked " + position);
        }
    });
    System.out.println("after listener");

下面ContactList是具有联系人姓名,号码,和字节[]为imageBlob一类。如果图像为null我设置默认ic_launcher作为接触式图像。适配器类是:

Here ContactList is a class which has contact name, number, and byte[] for imageBlob. If the image is null I set the default ic_launcher as a contact image. The adapter class is:

public class ContactListAdapter extends ArrayAdapter<ContactList> {

    Context context;
    int layoutResourceId;
    ContactList objects[] = null;

    View row;

    public ContactListAdapter(Context context, int layoutResourceId, ContactList[] objects) {
        super(context, layoutResourceId, objects);
        // TODO Auto-generated constructor stub

        this.context = context;
        this.layoutResourceId = layoutResourceId;
        this.objects = objects; 
        System.out.println(objects[1].getName());
        System.out.println(objects[1].getNumber());
        System.out.println(objects[1].getImageIcon());
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        row = convertView;
        final ContactListHolder holder;

        if ( row == null ) {

            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new ContactListHolder();
            holder.image    = (ImageView) row.findViewById(R.id.contactImage);
            holder.name     = (TextView) row.findViewById(R.id.contactName);
            holder.number   = (TextView) row.findViewById(R.id.contactNumber);
            holder.check    = (CheckBox) row.findViewById(R.id.selectedContact);

            row.setTag(holder);

        } else {

            holder = (ContactListHolder)row.getTag();
        }

        ContactList contact = objects[position];
        if(contact.imageIcon != null) {

            Bitmap imgBitmap = BitmapFactory.decodeByteArray(contact.imageIcon, 0, contact.imageIcon.length);
            holder.image.setImageBitmap(imgBitmap);
        } else {

            holder.image.setImageResource(R.drawable.ic_launcher);
        }

        holder.name.setText(contact.name);
        holder.number.setText(contact.number);
        holder.check.setChecked(objects[position].isSelected());    

        return row;

    }

    static class ContactListHolder {

        ImageView image;
        TextView name;
        TextView number;
        CheckBox check;
    }
}

我有100多个联系人,以便只增加3个对象。在这个联系人列表中我成功地获得接触式图像,姓名,号码。

I Have more than 100 contacts so added only 3 objects. In this contact list I successfully receive contact image, name, number.

有什么问题在的ListView 是无法点击?我希望ü的任何一个会指导我。先谢谢了。

What is the problem the ListView is unable to click? I hope any one of u will guide me. Thanks in advance.

感谢所有。现在得到的结果只需添加机器人:可聚焦在我的所有子视图=假。感谢UR guidings。

Thanks to all. now got the result by just adding android:focusable="false" in my all child views. thanks for ur guidings.

推荐答案

在嵌套视图,子视图总是先得到所有的触摸事件。如果你想父视图(在你的情况,在ListView行),得到一个触摸事件,你必须返回false对孩子的事件,或将它们设置为机器人:可点击=假在清单中。

in nested Views, the child view always gets all the touch events first. if you want the parent view (in your case, the listView row), to get a touch event, you must return false on the child events or set them to be android:clickable="false" in the manifest.

这篇关于我不能点击Android的ListView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆