ListView控件不听OnClickListener [英] ListView doesn't listens to OnClickListener

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

问题描述

我有以下的code在我的应用程序:

I have the following code in my app:

                        AnotherCursorAdapter adapter = new AnotherCursorAdapter(CadItemActivity.this, 
                                                                                R.layout.imgsinternas, 
                                                                                cursorImagens, 
                                                                                new String[] {"nome", "tags",},
                                                                                new int[] { R.id.txtNome, R.id.txtTags });
                        telaScroll.setAdapter(adapter);


    telaScroll.setClickable(true);
    telaScroll.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> av, View v, int pos, long id) {
            Log.d("1212121", "OnClick"); 
            // return false;
        }
    });        

code为AnotherCursorAdapter:

Code for AnotherCursorAdapter:

public class AnotherCursorAdapter extends SimpleCursorAdapter {

    private LayoutInflater inflater;
    public AnotherCursorAdapter(Context context, 
                                int layout, 
                                Cursor c,
                                String[] from, 
                                int[] to) {
        super(context, layout, c, from, to);
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
             // get the views from the row
             TextView name = (TextView) view.findViewById(R.id.txtNome);
             TextView tags = (TextView) view.findViewById(R.id.txtTags);
             ImageView img = (ImageView) view.findViewById(R.id.figura);
            //asign the values
             name.setText(cursor.getString(4)); 
             tags.setText(cursor.getString(3)); 

             name.setClickable(true);
             tags.setClickable(true);
             img.setClickable(true);


    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View v = inflater.inflate(R.layout.imgsinternas, null);
        return v;
    }
}

telaScroll是我的数据库填充一个ListView。我不是从ListActivity延长。

telaScroll is a ListView populated by my database. I am not extending from ListActivity.

在code以上不起作用!

The code above DOESN'T work!

该事件不会被触发!

我是什么做错了吗? =(

What am I doing wrong? =(

推荐答案

尝试设置onClickListener您在您的列表项文本和/或图像,同时具有约束力。

Try setting onClickListener for your text and/or image in your list item while binding.

@Override     
public void bindView(View view, Context context, Cursor cursor) {              
    // get the views from the row         
    TextView name = (TextView) view.findViewById(R.id.txtNome);         
    TextView tags = (TextView) view.findViewById(R.id.txtTags);          
    ImageView img = (ImageView) view.findViewById(R.id.figura);        
    //asign the values          
    name.setText(cursor.getString(4));              
    tags.setText(cursor.getString(3));            
    name.setClickable(true);          
    tags.setClickable(true);           
    img.setClickable(true);

    name.setOnClickListener( new OnClickListener()) {
        public void onClick(View v) {
             // code for performing action on click
        }
    });

    img.setOnClickListener( new OnClickListener()) {
        public void onClick(View v) {
             // code for performing action on click
        }
    });

} 

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

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