Skip to content Skip to sidebar Skip to footer

Remove Id Of Item Clicked In List View

| Icon(image) | Title(text) | cross(image) | | | Description(text)| | | | | coupon(image) | Its a list

Solution 1:

Here is the answer for NewBies like Me...

<ImageView
    android:id="@+id/list_item_iv_icon_cross"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignParentRight="true"
    android:clickable="true"
    android:contentDescription="@string/app_name"        
    android:src="@drawable/cross_selector"
    android:onClick="onCrossClick" />

i used onClick on item and to get position in which it has been clicked i used

finalint position = listView.getPositionForView((View) v.getParent());

full code :-

publicvoidonCrossClick(View v){

    finalint position = listView.getPositionForView((View) v.getParent());
    Toast.makeText(this, "click on button " + position, Toast.LENGTH_LONG)
            .show();        
}

Solution 2:

Check below Sample code :

publicclassListViewAdapter_testextendsBaseAdapter {

            private LayoutInflater mInflater;

            publicListViewAdapter_test(Context con) {
                // TODO Auto-generated constructor stub
                mInflater = LayoutInflater.from(con);
            }

            publicintgetCount() {
                // TODO Auto-generated method stubreturn a_product_id.size();
            }

            public Object getItem(int position) {
                // TODO Auto-generated method stub// return product_id1.size();return position;
            }

            publiclonggetItemId(int position) {
                // TODO Auto-generated method stub// return product_id1.get(position).hashCode();return position;
            }

            public View getView(finalint position, View convertView,
                    ViewGroup parent) {
                // TODO Auto-generated method stubfinal ListContent holder;
                Viewv= convertView;
                if (v == null) {
                    v = mInflater.inflate(R.layout.scan_row1, null);
                    holder = newListContent();

                    holder.name = (TextView) v.findViewById(R.id.sc_textname);

                    holder.name1 = (TextView) v.findViewById(R.id.sc_review);

                    holder.ratings = (RatingBar) v.findViewById(R.id.sc_ratingBar1);

                    holder.total_rate = (Button) v.findViewById(R.id.button1);

                    holder.img_p = (ImageView) v.findViewById(R.id.image_prod);

                    // holder.total_rate.setOnClickListener(mOnTitleClickListener1);


                    v.setTag(holder);
                } else {

                    holder = (ListContent) v.getTag();
                }


                holder.total_rate.setOnClickListener(mOnTitleClickListener3);

                holder.img_p.setOnClickListener(mOnTitleClickListener_image);

                return v;
            }
        }

        staticclassListContent {

            ImageView img_p;
            TextView name1;
            TextView name;
            RatingBar ratings;
            Button total_rate;

        }

        publicOnClickListenermOnTitleClickListener3=newOnClickListener() {
            publicvoidonClick(View v) {
                finalintposition= list_v
                        .getPositionForView((View) v.getParent());

                Log.d("you are click on Ratings","you are click on Ratings");

            }
        };

            publicOnClickListenermOnTitleClickListener_image=newOnClickListener() {
            publicvoidonClick(View v) {
                finalintposition= list_v
                        .getPositionForView((View) v.getParent());

                Log.d("you are click on image view","you are click on image view");


            }
        };

Post a Comment for "Remove Id Of Item Clicked In List View"