我想在 activity 中使用一個 Textview 來查看數(shù)據(jù)庫。setText()代碼:@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewlogs);
TextView tv = (TextView) findViewById(R.id.tvSqlinfo);
LogsDB info = new LogsDB(this);
info.open();
ArrayList<String> data = info.getData();
info.close();
tv.setText(data);
}好像在 tv.setText(data);處獲的錯誤:"The method setText(CharSequence) in the type TextView is not applicable for the arguments (ArrayList)"。然后當(dāng)我建議修復(fù)時,tv.setText(data)就變成 tv.setText((CharSequence) data);。當(dāng)我檢測程序時,有錯誤顯示它不能被cast。如何在 Textview 來查看數(shù)據(jù)庫?
1 回答

墨色風(fēng)雨
TA貢獻(xiàn)1853條經(jīng)驗 獲得超6個贊
0.0 你的data是個Arrylist,把它里面的數(shù)據(jù)遍歷出來再settext();
ArrayList data = info.getData();
info.close();
String s = "";
//數(shù)據(jù)多的時候用線程遍歷~
for(int i = 0; i<data.size(); i++){
s = s + data.get(i);
}
tv.setText(s);
添加回答
舉報
0/150
提交
取消