我是Android应用程序开发的新手。在我的活动中,我尝试使用Textview查看我的数据库。
这是我的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(数据)得到和错误;。声明“setText(CharSequence)类型中的方法TextView不适用于参数(ArrayList)”,那么当我执行建议的修复时,它会更改
tv.setText(data)至
tv.setText((CharSequence) data);然后,当我测试应用程序时,我会得到一个错误,说明它不能进行强制转换。为了能够在文本视图中查看我的数据库,我需要更改什么?
如有任何建议和帮助,将不胜感激。谢谢
发布于 2013-09-23 01:21:04
如果你想保持简单,你可以用
tv.setText(data.toString());而不是
tv.setText(data);它将显示如下所示:(field1,field2,.)
发布于 2013-09-23 01:10:40
您可能希望将每个String从ArrayList中取出,并将它们添加到单个String对象中,然后将其添加到TextView中。有点像
String text = "These are my database Strings ";
for (int i=0; i<data.size(), i++)
{
text = text.concat(data.get(i)); // might want to add a space, ",", or some other separator
}
tv.setText(text);您可以分离String,但是您希望它们被显示出来。
https://stackoverflow.com/questions/18950355
复制相似问题