gpt4 book ai didi

android - 如何在没有布局的情况下更改 ListView 的行属性?

转载 作者:太空狗 更新时间:2023-10-29 13:39:44 25 4
gpt4 key购买 nike

好时机!我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com