Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
要列出的Android/java sqlite数据_Android_Sqlite - Fatal编程技术网

要列出的Android/java sqlite数据

要列出的Android/java sqlite数据,android,sqlite,Android,Sqlite,我正在学习一个教程,我已经创建了一个数据库类和一个活动类。这是我的活动课: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); datasource = new CommentsDataSource(this); datasource.open(); List<C

我正在学习一个教程,我已经创建了一个数据库类和一个活动类。这是我的活动课:

  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    datasource = new CommentsDataSource(this);
    datasource.open();

    List<Comment> values = datasource.getAllComments();

    // Use the SimpleCursorAdapter to show the
    // elements in a ListView
    ArrayAdapter<Comment> adapter = new ArrayAdapter<Comment>(this,
        android.R.layout.simple_list_item_1, values);
    setListAdapter(adapter);
  }
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
数据源=新注释数据源(此);
datasource.open();
列表值=datasource.getAllComments();
//使用SimpleCursorAdapter显示
//ListView中的元素
ArrayAdapter=新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,值);
setListAdapter(适配器);
}
我的数据库有点不同,但大部分内容与教程中的内容相同。Comment只是一个setter/getter类。 现在的问题是,在我的列表中,我想显示注释名称,但我得到了“com.example.blabla”。Comment@40dca9d0". 我认为这是因为我正在将整个comment类传递给适配器。如何正确传递姓名

这是到教程的链接,我一定错过了一些东西,因为它似乎在那里工作,但我不知道具体是什么:

你确定把这个添加到你的评论类了吗?
在java中,toString()的默认实现是Class@Hashcode这就是您当前显示的内容,因此您需要通过返回注释来覆盖默认实现。

您没有看到调用toString(),因为它在(第2段)中显示

无论文本视图是如何引用的,它都将填充 数组中每个对象的toString()。您可以添加 自定义对象。将对象的toString()方法重写为 确定将为列表中的项目显示哪些文本


谢谢,现在可以用了:)。。。但是您还知道在这种情况下调用“toString”方法的位置/方式/原因吗?我在代码中看不到它,所以它必须在某个地方自动调用?更新以回答您的评论。
  // Will be used by the ArrayAdapter in the ListView
  @Override
  public String toString() {
    return comment;
  }