我用 ArrayList 创建了一个 TextView,但输出没有显示任何文本,我做错了什么?xml 中定义了所有不同的视图,包括图像视图和多个文本视图,但我似乎无法让它显示任何文本。
文本项.java:
public class TextItem {
private int imageId;
private String description;
private String description_real;
private String openingtimes;
private String openingtimes_real;
private String prices;
private String prices_real;
public TextItem(int imageId,
String description,
String description_real,
String openingtimes,
String openingtimes_real,
String prices,
String prices_real) {
this.imageId = imageId;
this.description = description;
this.description_real = description_real;
this.openingtimes = openingtimes;
this.openingtimes_real = openingtimes_real;
this.prices = prices;
this.prices_real= prices_real;
}
public int getImageId() {
return imageId;
}
public void setImageId(int imageId) {
this.imageId = imageId;
}
public String getdescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getdescription_real() {
return description_real;
}
public void setdescription_real(String description_real) {
this.description_real = description_real;
}
public String getopeningtimes(){
return openingtimes;
}
public void setopeningtimes(String openingtimes) {
this.openingtimes = openingtimes;
}
public String getopeningtimes_real(){
return openingtimes_real;
}
public void setopeningtimes_real(String openingtimes_real) {
this.openingtimes_real = openingtimes_real;
}
public String prices(){
return prices;
}
public void setprices(String prices) {
this.prices = prices;
}
public String getprices_real(){
return prices_real;
}
public void setprices_real(String prices_real) {
this.prices_real = prices_real;
}
@Override
public String toString() {
return description + "\n" + description_real + "/n" + "/n" +
openingtimes + "\n" + openingtimes_real + "/n" + "/n" +
prices + "\n" + prices_real + "/n" + "/n" ;
}}
空气.java:
public class Air extends Activity {
public static final String[] description = new String[] {"Lorem"};
public static final String[] description_real = new String[] {"Lorem"};
public static final String[] openingtimes = new String[] { "Lorem"};
public static final String[] openingtimes_real = new String[] {"Lorem"};
public static final String[] prices = new String[] { "Lorem"};
public static final String[] prices_real = new String[] {"Lorem"};
public static final Integer[] images = {
R.drawable.hotel };
ImageView ImageView;
TextView TextView;
List<TextItem> TextItems;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.textview_item);
TextItems = new ArrayList<TextItem>();
for (int i = 0; i < description.length ; i++) {
TextItem item = new TextItem(images[i],
description[i],
description_real[i],
openingtimes[i],
openingtimes_real[i],
prices[i],
prices_real[i]);
TextItems.add(item);
ImageView = (ImageView) findViewById(R.id.picture);
TextView = (TextView) findViewById(R.id.description);
TextView = (TextView) findViewById(R.id.description_real);
TextView = (TextView) findViewById(R.id.openingtimes);
TextView = (TextView) findViewById(R.id.openingtimes_real);
TextView = (TextView) findViewById(R.id.prices);
TextView = (TextView) findViewById(R.id.prices_real);
}
}
}
.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:contentDescription="@string/image"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/picture"
android:paddingBottom="10dp"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/description_real"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/description"
android:paddingLeft="10dp"
android:textColor="#666666"
android:textSize="14sp" />
<TextView
android:id="@+id/openingtimes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/description_real"
android:paddingBottom="10dp"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/openingtimes_real"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/openingtimes"
android:paddingLeft="10dp"
android:textColor="#666666"
android:textSize="14sp" />
<TextView
android:id="@+id/prices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/openingtimes_real"
android:paddingBottom="10dp"
android:textColor="#000000"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/prices_real"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/prices"
android:paddingLeft="10dp"
android:textColor="#666666"
android:textSize="14sp" />
</RelativeLayout>