0

我有一个自定义列表视图。此 ListView 包含 1 个 Image 和 3 个 TextView。如何单击 ImageView 并获取当前位置。(不要点击其他元素,只点击ImageView)

4

1 回答 1

1

在您的自定义适配器类中,您有 getView(.. .. ..) 方法:

@Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
//     >>>    >>>                 ^^^^^^  This is your posotion = index

        View row = convertView;
        Your_Holder holder = null;
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(resId, parent, false);
            holder = new Your_Holder();

            ....
            ....
            holder.yourImageView = (ImageView) row.findViewById(R.id.yourImageID);
            ....
            ....

            row.setTag(holder);
        }
        else{
            holder = (Your_Holder)row.getTag();
        }

   //    Set here your images click event
        holder.yourImageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                System.out.println("Position = " + position)

            }
        });

    }
于 2012-10-13T11:47:10.053 回答