Android 通过自定义适配器设置多个文本视图的文本
在使用自定义适配器的自定义列表布局中设置多个文本视图的文本时遇到问题。以下是我的列表项布局:Android 通过自定义适配器设置多个文本视图的文本,android,android-adapter,Android,Android Adapter,在使用自定义适配器的自定义列表布局中设置多个文本视图的文本时遇到问题。以下是我的列表项布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:padding="6dip" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dp"
android:contentDescription="TODO"
android:src="@drawable/blue_circle" />
<TextView
android:id="@+id/short_content"
android:layout_width="wrap_content"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/icon"
android:ellipsize="marquee"
android:text="content"
android:singleLine="true"
android:textSize="12sp" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/short_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/icon"
android:gravity="center_vertical"
android:text="Title"
android:textSize="16sp" />
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/short_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/icon"
android:gravity="right"
android:text="date"
android:textSize="13sp" />
}
这里是我实例化适配器的地方
listView = (ListView) getView().findViewById(R.id.list_view_messages);
MessageAdapter adapter = new MessageAdapter(context, R.layout.messages_layout, textContentList);
listView.setAdapter(adapter);
唯一显示的是getShortContent,但由于某种原因,它不是getTitle或getCreated。我100%确定文本内容的所有字段都设置了文本。我猜出来了。我版面中的文本视图重叠,因此其他文本视图中的内容隐藏在后面 发布
TextContent
类,确保您在创建textContentList
时拥有所有数据。演示如何使用数据填充textContentList
,以及使用哪些数据。我恐怕无权发布如何填充列表,但我110%确定列表中填充了适当的内容是的。我刚试过。这没有帮助我认为textViewTitle和textViewDate为空,请交叉检查。
public class TextContent implements Serializable{
private String GUID, created, modified, deleted, name, message, title, shortContent, fullContent, author, language, person;
public TextContent(){
}
public TextContent(String GUID, String created, String modified, String deleted, String name, String message, String title,
String shortContent, String fullContent, String author, String language, String person) {
this.GUID = GUID;
this.created = created;
this.modified = modified;
this.deleted = deleted;
this.name = name;
this.message = message;
this.title = title;
this.shortContent = shortContent;
this.fullContent = fullContent;
this.author = author;
this.language = language;
this.person = person;
}
public String getGUID() {
return GUID;
}
public String getCreated() {
return created;
}
public String getModified() {
return modified;
}
public String getDeleted() {
return deleted;
}
public String getName() {
return name;
}
public String getMessage() {
return message;
}
public String getTitle() {
return title;
}
public String getShortContent() {
return shortContent;
}
public String getFullContent() {
return fullContent;
}
public String getAuthor() {
return author;
}
public String getLanguage() {
return language;
}
public String getPerson() {
return person;
}
public void setGUID(String GUID) {
this.GUID = GUID;
}
public void setCreated(String created) {
this.created = created;
}
public void setModified(String modified) {
this.modified = modified;
}
public void setDeleted(String deleted) {
this.deleted = deleted;
}
public void setName(String name) {
this.name = name;
}
public void setMessage(String message) {
this.message = message;
}
public void setTitle(String title) {
this.title = title;
}
public void setShortContent(String shortContent) {
this.shortContent = shortContent;
}
public void setFullContent(String fullContent) {
this.fullContent = fullContent;
}
public void setAuthor(String author) {
this.author = author;
}
public void setLanguage(String language) {
this.language = language;
}
public void setPerson(String person) {
this.person = person;
}
listView = (ListView) getView().findViewById(R.id.list_view_messages);
MessageAdapter adapter = new MessageAdapter(context, R.layout.messages_layout, textContentList);
listView.setAdapter(adapter);