gpt4 book ai didi

java - Sugar ORM 库数据未正确检索

转载 作者:行者123 更新时间:2023-11-30 02:15:49 26 4
gpt4 key购买 nike

我使用 sugar orm 库添加数据和检索数据但是数据没有正确检索下面是我的代码主.xml

  <EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edtTitle"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edtEdition"
android:layout_below="@+id/edtTitle"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save"
android:id="@+id/buttonSave"
android:layout_below="@+id/edtEdition"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="47dp" />

<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/buttonSave" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display"
android:id="@+id/buttonDisplay"
android:layout_above="@+id/listView"
android:layout_toRightOf="@+id/buttonSave"
android:layout_toEndOf="@+id/buttonSave" />

书.java

public class Book extends SugarRecord<Book> {

String title;
String edition;

public Book()
{

}

public Book(String title,String edition)
{
this.title=title;
this.edition=edition;
}
}

主 Activity .java

public class MainActivity extends ActionBarActivity {

EditText title,edition;
Button saveButton;
ListView listView;
List<Book> list;



@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

title=(EditText)findViewById(R.id.edtTitle);
edition=(EditText)findViewById(R.id.edtEdition);
listView= (ListView) findViewById(R.id.listView);

saveButton= (Button) findViewById(R.id.buttonSave);

list= Book.listAll(Book.class);
ArrayAdapter<Book> adapter = new ArrayAdapter<Book>(MainActivity.this, android.R.layout.simple_list_item_1, Integer.parseInt(list.toString()));

listView.setAdapter(adapter);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Book book = new Book(title.getText().toString(),edition.getText().toString());
// Book book = new Book("hello","World");

book.save();

}
});
}
}

我想检索数据并显示在 ListView 中数据显示在 ListView 中,但像这种类型的“@azx1lz”它不是当前数据所以如何提前检索当前数据

最佳答案

添加toString方法

公共(public)类 Book 扩展了 SugarRecord{

String title;
String Edition;

public Book()
{

}
public Book(String title,String Edition)
{
this.title=title;
this.Edition=Edition;
}

@Override
public String toString() {
return title + '\'' +
Edition ;
}

关于java - Sugar ORM 库数据未正确检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29362336/

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