好时机! 我的 Android 应用程序具有这样的功能,我在没有 ListView 布局的 TabHost 页面之一中使用 ListView。像那样:
ListView lv = new ListView(this);
lv.setAdapter(myAdapter);
所以我想更改某些行的属性,例如行中的文本大小。那么,例如,我如何才能访问 ListView 显式行的属性以更改文本大小?
最佳答案
使用 BaseAdapter 并在 getView 调用中修改字体大小。
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_layout, null);
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// Change text size
holder.text.setTextAppearance(context,R.style.customStyle);
return convertView;
}
static class ViewHolder {
TextView text;
}
并且您可以在 getView 调用中使用位置变量来更改特定行。希望这有帮助!!!
关于android - 如何在没有布局的情况下更改 ListView 的行属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7233375/