如何使一个ImageView的点击在列表视图视图、列表、ImageView

由网友(北陌离歌)分享简介:我已经创建了一个基本的列表视图,并在其中添加一个TextView和ImageView的。Hi i have created a basic listview and added a textview and imageview in it.我已经创建了一个基本的列表视图,并在其中添加一个TextView和ImageView的。

Hi i have created a basic listview and added a textview and imageview in it.

        

<ImageView
    android:id="@+id/icon"
    android:layout_width="50px"
    android:paddingLeft="2px"
    android:paddingRight="2px"
    android:paddingTop="2px"
    android:layout_height="wrap_content"
    android:layout_alignParentRight = "true"
    android:src="@drawable/call"
/>

我需要做的ImageView点击,这样,如果它的一些点击的动作会发生像一个新的活动opened.Can有人帮助我如何做到这一点。

I need to make imageview clickable so that if some clicks on it an action will happen like an new activity is opened.Can someone help me how to do this.

感谢

推荐答案

您必须实现自己的光标适配器,在你不得不重写 getView 方法然后设置的onclick 监听到你的形象:

You have to implement your own cursor adapter, and in that you have to override the getView method and then set the onclick listener to your image:

public class SMSimpleCursorAdapter extends SimpleCursorAdapter{

    Context context;
    Activity activity;
    public SMSimpleCursorAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.context=context;
        this.activity=(Activity) context;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        View view = super.getView(position, convertView, parent);
        long id=getItemId(position);
        ImageView image= (ImageView)view.findViewById(R.id.icon);
        image.setOnClickListener(new OnClickListener() 
        {
            @Override
            public void onClick(View v) 
            {

            }
        });


    }

}
阅读全文

相关推荐

最新文章