Reputation: 1407
I am writing aplication for android 2.3
in main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "fill_parent"
android:layout_height= "fill_parent" >
<ListView
android:id = "@android:id/list"
android:textSize = "4sp"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:drawSelectorOnTop = "false" />
</LinearLayout>
in ViewHolder.java
public class ViewHolder {
ImageView icon = null;
ViewHolder(View base){
this.icon = (ImageView)base.findViewById(R.id.pic);
}
}
in ViewHolderDemo.java
public class ViewHolderDemo extends ListActivity {
private static final String[] items = {"lorem", "ipsum", "dolor", "sit", "amet","consectetuer", "adipiscing", "elit"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setListAdapter(new IconicAdapter());
}
public void OnListItemClick(ListView parent, View v, int position, long id){
}
class IconicAdapter extends ArrayAdapter<String> {
public IconicAdapter() {
super(ViewHolderDemo.this, R.layout.row, R.id.label, items);
}
public View getView(int position, View convertView, ViewGroup parent){
View row = super.getView(position, convertView, parent);
ViewHolder holder = (ViewHolder)row.getTag();
if(holder == null){
holder = new ViewHolder(row);
row.setTag(holder);
}
holder.icon.setImageResource(R.drawable.star);
return(row);
}
}
}
problem that tired me is : when i changeandroid:textSize
in .xml
. size of text dont change
may be this is a bug in android
so how i can chage size of text(make small) that exist in ListView?
Upvotes: 1
Views: 203
Reputation: 2084
android:textSize = "4sp"
android:textSize is a TextView attribute, not for ListView.
You can override the default textSize by setting the textSize in your app theme. The better way would be to either:
Why this is better than setting it in the app theme? Since the textSize attribute would be shared by all widgets that extend from TextView. So anything like Button or EditText would have that size as well (of course assuming that is not the desired effect).
Upvotes: 2
Reputation: 133560
private static final String[] items = {"lorem", "ipsum", "dolor", "sit", "amet","consectetuer", "adipiscing", "elit"}
I assume you are inflating a custom layout with imageview and textview.
In your getView()
SpannableString ss2= new SpannableString(items[position]);
ss2.setSpan(new RelativeSizeSpan(2f), 0, ss2.length(), 0); //change the size
viewHolder.tv.setText(ss2); //set spannable string to your text
Upvotes: 1
Reputation: 179
You can do so with a custom row XML and BaseAdapter. Not sure if there's an easier way or not, but I know this works.
Upvotes: 1