Java-Sugar ORM:如何显示值

Java-Sugar ORM:如何显示值,第1张

概述我通过AndroidStudio使用SugarORM进行Android开发.但是我想我有一个非常类似的问题.如何将一个/多个结果查询显示为String或int?我的实体看起来像这样:publicclassPersonsDatabaseextendsSugarRecord<PersonsSelection>{StringadultText,childText;intadultCount,chil

我通过Android Studio使用Sugar ORM进行AndroID开发.

但是我想我有一个非常类似的问题.
如何将一个/多个结果查询显示为String或int?
我的实体看起来像这样:

public class PersonsDatabase extends SugarRecord<PersonsSelection>{String adultText, childText;int adultCount, childCount;public PersonsDatabase(){}public PersonsDatabase(String adultText, String childText, int adultCount, int childCount){    this.adultText = adultText;    this.childText = childText;    this.adultCount = adultCount;    this.childCount = childCount;    this.save();}

}

它可以正确保存.但是当我想这样显示时:

public class PersonsSelection extends Activity {ListVIEw List;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_persons_selection);    PersonsDatabase personsDatabase = new PersonsDatabase("1 Adult","No Childs",1,0);    List<PersonsDatabase> personsList = PersonsDatabase.finDWithquery(PersonsDatabase.class,"Select adult_Text from PERSONS_DATABASE");    List = (ListVIEw)findVIEwByID(R.ID.ListVIEw);    List.setAdapter(new ArrayAdapter<PersonsDatabase>(this, androID.R.layout.simple_List_item_1, personsList));}

}

我得到的东西是:PACKAGEname.PersonsDatabase@4264c038
但是我想要我在构造函数中编写的值.

感谢帮助.

解决方法:

从docs on ArrayAdapter

However the TextVIEw is referenced, it will be filled with the toString() of each object in the array. You can add Lists or arrays of custom objects. OverrIDe the toString() method of your objects to determine what text will be displayed for the item in the List.

简而言之:只需在PersonsDatabase类中重写toString()方法即可返回所需的文本表示形式.

或者:

To use something other than TextVIEws for the array display, for instance, ImageVIEws, or to have some of data besIDes toString() results fill the vIEws, overrIDe getVIEw(int, VIEw, VIEwGroup) to return the type of vIEw you want.

(再次来自文档).关于如何执行此 *** 作的大量示例.

总结

以上是内存溢出为你收集整理的Java-Sugar ORM:如何显示值全部内容,希望文章能够帮你解决Java-Sugar ORM:如何显示值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1077822.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存