0

あなたは画像でそれをチェックすることができます私はリストビューで2つのビューを持っています左側の画像ビューと右側のボタンビュー他はテキストビューですが、画像ビューの呼び出しが別のアクティビティを開始するときに別のアクティビティを呼び出す必要がありますリストビューで特定のボタンまたは画像のクリックイベントを取得します

アクティビティClass.java

liststipciations.setOnItemClickListener(new OnItemClickListener() {

    public void onItemClick(AdapterView<?> parent, View view, int position,
            long l) {


    Log.e("list stipcitaions", "-->"+liststipciations.getItemIdAtPosition(position));



    }
});

アダプターClass.java

public class LazyAdapterStipciationsAdvertise extends BaseAdapter implements OnClickListener{

    private static final String TAG_SHOWTEXT="showtext";
    String showtext;

    private static final String TAG_PRODUCTINFO="product_info";
    String productinfo;

    private static final String TAG_THUMBIMAGE="thumbsrc";
    String thumbimage;

    private static final String TAG_STIPCIATED="stipciated";
    String stipciated;

    private static final String TAG_DISTANCE="distance";
    private Activity activity;
    private ArrayList<HashMap<String, String>> result; 
    private static LayoutInflater inflater=null;
    public GridImageLoader gridimageLoader; 
    int imageWidth;
    int imageheight;
    Context context; 
    int width;
    int height;

    int layoutwidth;
    int layoutheight;

    public LazyAdapterStipciationsAdvertise(Activity a, ArrayList<HashMap<String, String>> r)
    {
        activity = a;
        result=r;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        gridimageLoader=new GridImageLoader(activity.getApplicationContext());

        width = a.getWindowManager().getDefaultDisplay().getWidth();
        height=a.getWindowManager().getDefaultDisplay().getHeight();

        imageWidth = ((width*18)/100);
        layoutheight=((height*20)/100);



    }

    public int getCount() {
        return result.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public static class ViewHolder
    {
        public TextView textpromotional;
        public TextView textdistance;
        public ImageView imageadvertise;
        public ImageView imagestipciate;
        public ImageView imagestipciated;

    }

    public View getView(int position, View convertView, ViewGroup parent) 
    {
        View vi=convertView;
        ViewHolder holder;
        if(convertView==null)
        {
            vi = inflater.inflate(R.layout.stipciationslist, null);
             holder=new ViewHolder();
            holder.textpromotional=(TextView)vi.findViewById(R.id.textpromotional);
            holder.textdistance=(TextView)vi.findViewById(R.id.textdistance);
            holder.imageadvertise=(ImageView)vi.findViewById(R.id.imageadvertise);
            holder.imageadvertise.setLayoutParams(new LinearLayout.LayoutParams(imageWidth,imageWidth));

            holder.imagestipciate=(ImageView)vi.findViewById(R.id.imagestipciate);
            holder.imagestipciated=(ImageView)vi.findViewById(R.id.imagestipciated);
            vi.setTag(holder);
        }
        else

            holder=(ViewHolder)vi.getTag();


        holder.textpromotional.setText(result.get(position).get(TAG_SHOWTEXT));
        holder.textdistance.setText(result.get(position).get(TAG_DISTANCE));
        holder.imageadvertise.setTag(result.get(position).get(TAG_THUMBIMAGE));
        holder.imageadvertise.setId(1);

        if(result.get(position).get(TAG_STIPCIATED).equals("1"))
        {
            holder.imagestipciated.setVisibility(View.VISIBLE);
            holder.imagestipciated.setId(2);
            holder.imagestipciate.setVisibility(View.INVISIBLE);
        }
        if(result.get(position).get(TAG_STIPCIATED).equals("0"))
        {
            holder.imagestipciate.setVisibility(View.VISIBLE);
            holder.imagestipciate.setId(3);
            holder.imagestipciated.setVisibility(View.INVISIBLE);
        }
        gridimageLoader.DisplayImage(result.get(position).get(TAG_THUMBIMAGE), activity, holder.imageadvertise);
        return vi;
    }

    public static float convertDpToPixel(float dp, Context context){
        Resources resources = context.getResources();
        DisplayMetrics metrics = resources.getDisplayMetrics();
        float px = dp * (metrics.densityDpi/160f);
        return px;
    }


}

ここに画像の説明を入力してください

4

1 に答える 1

2

setOnClickListenerボタンと画像のgetViewメソッドを実装できます。以下のコードがお役に立てば幸いです。

Button myButton

public View getView(int position, View convertView, ViewGroup parent)
{
    myButton = (Button)convertView.findViewById(R.id.myButton);

    myButton.setOnClickListener(new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            Intent intent = new Intent(CurrentActivity.this, OtherActivity.class);
            startActivity(intent);
        }
    });
}
于 2013-03-14T06:01:51.373 に答える