In my list view inflator i have an image and a textview. When the user selects the any item in the listview, I want to increase the font size of the text in the textview. I am using a custom adapter. Can I do this in getview method ? And also is it possible to do this without calling notifydatasetchanged() always ?
Asked
Active
Viewed 5,300 times
3
-
have you created a custom adapter..??? – Wolverine May 28 '12 at 12:41
-
you should use design pattern `Holder` to full control over elements in `ListView`, without it you are not able to do it. This solution is cleanest and right programmatically written. – Simon Dorociak May 28 '12 at 12:45
3 Answers
1
You can use setTag()
and getTag()
.
setTag() in your adapter's getView()
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView= getLayoutInflater().inflate(R.layout.layoutfile, null);
TextView mTextViewNumber= (TextView) convertView.findViewById(R.id.TvId);
ImageView mImageView= (ImageView) convertView.findViewById(R.id.ImgId)
mTextViewNumber.setText("Hi hello");
mImageView.setBackgroundResource(R.x.xxxx);
convertView.setTag(mTextViewNumber, R.id.TvId);
convertView.setTag(mImageView, R.id.ImgId);
return convertView;
}
Change the Textsize by getTag() OnItemClickListener().
mListView=(ListView) findViewById(R.id.list_call_log_listview);
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
TextView mTextView= (TextView) view.getTag(R.id.TvId);
mTextView.setTextSize(20);
ImageView mImageView= (ImageView) view.getTag(R.id.ImgId);
mImageView.setBackgroundResource(R.x.xxxx);
}
});

Mohammed Azharuddin Shaikh
- 41,633
- 14
- 96
- 115
-
Thanks for your reply. Apart from changing the textsize I also have to change the background of the image when it is selected. (My inflator has a textview and a imageview). How can i use gettag() and settag() for multiple items ? And if i use the above code will i need to call notifydatasetchaged() ? Because i don't want to call it. – BlackberryChennai May 28 '12 at 12:55
-
see me answer again, made the changes for multiple control. – Mohammed Azharuddin Shaikh May 28 '12 at 12:59
-
Thanks this works, but after i click on an item a popup is shown. After coming back from the pop up the size is still big. I want it be become normal. – BlackberryChennai May 28 '12 at 13:57
-
take TextView and ImageView global, when return back from dialog change them normal. – Mohammed Azharuddin Shaikh May 28 '12 at 14:01
1
I think you can use this in your onItemClick method it's rather simple solution
View v=myListView.getChildAt(position);
TextView tv=(TextView)v.findViewById(R.id.myTextView);
tv.setTextSize(...);

user1049280
- 5,176
- 8
- 35
- 52
0
in adapter in getView function you can check the current item is selected item then can change the font and color in that if that is ture ...
or can use selector
how to change font color in selected/focused ListView items?

Community
- 1
- 1

Dheeresh Singh
- 15,643
- 3
- 38
- 36
-
http://stackoverflow.com/questions/6973914/change-listitem-view-on-select-in-listview – Dheeresh Singh May 28 '12 at 12:46