Skip to content Skip to sidebar Skip to footer

How To Set Id For Each Item In Listview

When I retrieve data from database, I have for each row unique ID I want match id with string in listview but ID I want it to be invisible, so that when i click any item in listv

Solution 1:

this should work

myAdapter.setViewBinder(newMyViewBinder());

publicclassMyViewBinderimplementsViewBinder {
@OverridepublicbooleansetViewValue(View view, Object data, String text){
    //Since it iterates through all the views of the item, change accordingly if(view instanceofTextView){ 
        ((TextView)view).setTag("whatever you want");
    }
}
}

Solution 2:

You can use custom adapter and use like this method to achive yor goal

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
    Viewvi= convertView;

    if(vi == null){
        vi = inflater.inflate(R.layout.row_layout, null);
    }

    finalintid= idGetFuncttion(position);

    vi.setOnClickListener(newOnClickListener() {

        @OverridepublicvoidonClick(View v) {
            doSomethingWithID(id);              
        }
    });

    return vi;      
}

Solution 3:

1.set your unique id toeach row by setTag propertyand retrieve it by getTag property2.use custom adapter andcustom listview layout for the listview andset your unique id to invisible textview incustom listview layout through custom adapter

Post a Comment for "How To Set Id For Each Item In Listview"