在ListView的Android简单的适配器显示 [英] Android simple adapter display in a listview
问题描述
下面是我。
公共类联系{ 私有String的firstName;
私人字符串的lastName;
私人字符串移动电话号码;
私人字符串homeNumber;
私人字符串workNumber;
私人字符串是homeAddress;
私人字符串EMAILADDRESS;
私人字符串招聘人数;
私人字符串说明;
私人诠释contactNumber; //构造函数和不重要了一堆getter和setter}
我有这样的语句:公共静态的ArrayList<联系与GT; contactList =新的ArrayList<联系与GT;();
在名为类 NewContact
这是我的主要的Android的Java类我的适配器code。
ArrayAdapter<联系与GT;适配器=新ArrayAdapter<联系与GT;(这一点,
R.layout.home_screen_contacts_view,NewContact.contactList);
问题如下,我想列表视图中只显示第一个和接触的姓氏,但目前它是显示,因为它是一个接触适配器,而不是一个字符串适配器包名和东西。
这是什么样子时,我添加联系人。
我的问题是,我该如何使用的接触类干将只显示名字和姓氏,当我做一个联系?
感谢您的时间。
编辑:我没有叫setter方法,但类变量是在构造函数中设置
。 NewContact.contactList.add(新联系(firstName.getText()。的toString()
lastName.getText()。toString()方法,mobileNumber.getText()。的toString()
homeNumber.getText()。toString()方法,workNumber.getText()。的toString()
homeAddress.getText()。toString()方法,emailAddress.getText()。的toString()
。workAddress.getText()的toString(),contactNotes.getText()的toString()));
覆盖的toString()
方法在联系
类这样它会返回一个concatination 的firstName
和的lastName
。
here is what I have.
public class Contact {
private String firstName;
private String lastName;
private String mobileNumber;
private String homeNumber;
private String workNumber;
private String homeAddress;
private String emailAddress;
private String workAddress;
private String notes;
private int contactNumber;
//A constructor and a bunch of getters and setters that are unimportant
}
I have this statement: public static ArrayList<Contact> contactList = new ArrayList<Contact>();
in a class named NewContact
.
This is my adapter code in my main android java class.
ArrayAdapter<Contact> adapter = new ArrayAdapter<Contact>(this,
R.layout.home_screen_contacts_view, NewContact.contactList);
The problem is as follows, I want the list view to just show the First and Last name of the contact but at the moment it is showing the package name and stuff because it is a contact adapter rather than a string adapter.
This is what it looks like when I add a contact.
My question is, how can I use the contact class getters to display just the first name and last name when i make a contact?
Thank you for your time.
EDIT: I have not called setters but the class variables are set in the constructor.
NewContact.contactList.add(new Contact(firstName.getText().toString(),
lastName.getText().toString(),mobileNumber.getText().toString(),
homeNumber.getText().toString(),workNumber.getText().toString(),
homeAddress.getText().toString(),emailAddress.getText().toString(),
workAddress.getText().toString(),contactNotes.getText().toString()));
Override toString()
method in the Contact
class so as it would return a concatination of firstName
and lastName
.
这篇关于在ListView的Android简单的适配器显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!