我是Android應用程序開發新手。我嘗試在我的活動中使用Textview查看我的數據庫。將setText()轉換爲數據庫的文本視圖
這裏是我的setText()的Java
@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(數據)是越來越和錯誤;.指出「在類型TextView的方法的setText(CharSequence的)是不適用的參數(ArrayList的)」然後,當我這樣做推薦修復它改變
tv.setText(data)
到
tv.setText((CharSequence) data);
然後當我測試該應用程序我收到一個錯誤,指出它不能被轉換。 我需要更改以便能夠在textview中查看我的數據庫?
任何意見和幫助,將不勝感激。 感謝
你可以使用data.toArray()。的toString() – nedaRM
'tv.setText(數據)'不適用於字符串數組?你不能將列表強制轉換爲CharSequence對象?您可以在數據列表的推移,一些字符串'tv.setText(data.get(0))'0是列表的指數 – Husam
太累了,但現在在數據庫中的值應該是它說「[email protected] 「 – ba2210