自定义光标适配器(获取位置)

Custom Cursor Adapter ( get position )

我想为我的图像视图设置可触摸以及如何在列表视图中获取每行图像视图的位置?

    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        // when the view will be created for first time,
        // we need to tell the adapters, how each item will look
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View retView = inflater.inflate(R.layout.list_shipments, parent, false);


        return retView;
    }


    @Override
    public void bindView(View view, Context context, Cursor cursor) {


    }
}

Cursor 已经定位在调用 newViewbindView 时的确切行。您只需要设置 onClick 或 OnTouch 侦听器:

@Override
public View newView(Context context, Cursor cursor, ViewGroup viewGroup)
{
    LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    View retView = inflater.inflate(R.layout.list_shipments, parent, false);
    ViewHolder holder = new ViewHolder(view);
    view.setTag(holder);
    return view;
}

@Override
public void bindView(View view, final Context context, Cursor cursor)
{
    ViewHolder holder = (ViewHolder) view.getTag();

    holder.image.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            // do something
        }
    }

ViewHolder的一些代码:

public static class ViewHolder
    {
        private ImageView image;
        public ViewHolder(View view)
        {
            image = (ImageView) view.findViewById(R.id.image);
        }
    }

@anil 这是我的 View.OnClickListener

中的代码
holder.img.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                String abc = holder.tv1.getText().toString();
                String def = holder.tv2.getText().toString();
                System.out.println(abc + def);

                String lat = abc;
                String lng = def;
                String[] countryValues = getResources().getStringArray(R.array.str_array_country_values);
                String country = SettingsActivity.getPreferencesStringValue(CursorAdapterActivity.this, 
                        SettingsActivity.KEY_COUNTRY_CODE, "");
                String uri = "";

                if (country.equals(countryValues[0])){
                    uri = "http://api.map.baidu.com/marker?location=" + lat + "," + lng + "&zoom=15&title= &content= &output=html";
                }
                else{
                    uri = "https://maps.google.com/maps?q=" + lat + "," + lng + "&z=15";    
                }
                startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
            }

        });