0

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

    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) {


    }
}
4

2 回答 2

0

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

@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);
        }
    }
于 2015-01-29T06:11:43.093 回答
-1

@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)));
            }

        });
于 2015-01-29T06:58:05.123 回答