gpt4 book ai didi

android - TextView 是 ListView 显示不正确

转载 作者:太空狗 更新时间:2023-10-29 14:21:34 25 4
gpt4 key购买 nike

我有一个从数据库中获取字符串并将其放入 ListView 的应用程序。这是从数据库中获取我的字符串的代码:

    public void setLogView(String date){


ArrayAdapter<TextView> adapter = new ArrayAdapter<TextView>(this, android.R.layout.simple_list_item_1);
listView.setAdapter(adapter);

DataBaseMain dataBase = new DataBaseMain(this);
dataBase.open();
String[][] all = dataBase.dayLog(date);
dataBase.close();

if(all == null)
return;

String temporay = "";

for(int j = 0; j < all[0].length; j++){
temporay = "";
for (int i = 0; i < all.length; i++){
TextView text = new TextView(this);
temporay = temporay + " " + all[i][j];
text.setText(temporay);
adapter.add((TextView)text);
}
}
}

我的 ListView 中似乎有新的 TextView,但文本乱七八糟。我检查了我的 temporay 字符串,没有问题。是在某处将他放在ListView 中。logcat 中没有错误或异常。这是我在我的应用程序 ListView 中得到的我想要的文本。(我想把 picuture 但我没有足够的重复:

enter image description here

最佳答案

在那里,从您提供的图像中可以清楚地看到

试试这个..

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
listView.setAdapter(adapter);

您的适配器用于附加 textView 对象而不是您提供的字符串。

然后在循环中添加 temporay 而不是 textView..like

 adapter.add(temporay);

这个,一定能解决你的问题。

关于android - TextView 是 ListView 显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16433774/

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