gpt4 book ai didi

java - 如何将列乘以ListView中的数字,Android

转载 作者:行者123 更新时间:2023-12-01 04:50:36 25 4
gpt4 key购买 nike

我从数据库中选择数据。一列中的数据,必须转换为千克,我需要乘以一列的系数。 sets_weight列中的数据以磅为单位,需要以公斤为单位显示,无需对数据库进行修改如何正确地做到这一点。有任何想法吗!谢谢!

onSets = db.getSets(exesIdsColExes, toprog_dif);    
listSets.setAdapter(new SimpleCursorAdapter(this,
R.layout.itemsets, onSets,
new String[] {"sets_ids", "sets_weight", "sets_ones"},
new int[] {R.id.itemsets_ids, R.id.itemsets_weight, R.id.itemsets_ones}) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
// Here we get the textview and set the color
Typeface fontTitleProg = Typeface.createFromAsset(getAssets(), "AGHELVETICA.TTF");
TextView itemsets_ids = (TextView) row.findViewById(R.id.itemsets_ids);
itemsets_ids.setTypeface(fontTitleProg, 1);
itemsets_ids.setGravity(0x05);

TextView itemsets_weight = (TextView) row.findViewById(R.id.itemsets_weight);
itemsets_weight.setTypeface(fontTitleProg, 1);
itemsets_weight.setGravity(0x01);

TextView itemsets_ones = (TextView) row.findViewById(R.id.itemsets_ones);
itemsets_ones.setTypeface(fontTitleProg, 1);
itemsets_ones.setGravity(0x01);

return row;
}
});

最佳答案

我从来没有做过任何android开发,但是the documentation of SimpleCursorAdapter说:

First, if a SimpleCursorAdapter.ViewBinder is available, setViewValue(android.view.View, android.database.Cursor, int) is invoked. If the returned value is true, binding has occured. If the returned value is false and the view to bind is a TextView, setViewText(TextView, String) is invoked. If the returned value is false and the view to bind is an ImageView, setViewImage(ImageView, String) is invoked.

因此,您只需要传递 SimpleCursorAdapter 的自定义实例,如果列索引为 1(第二列),它将从光标获取以磅为单位的值,将其相乘以将磅转换为千克,将结果设置为 View 的文本,并返回 true。对于其他列,返回 false。

关于java - 如何将列乘以ListView中的数字,Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15046650/

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