本文介绍了如何使一个ImageView的点击在列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个基本的列表视图,并在其中添加一个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) 
            {

            }
        });


    }

}

这篇关于如何使一个ImageView的点击在列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 01:00