我无法让我的数据显示在 ListView 中。我已经删除了所有不必要的代码以保持简单。该程序运行良好,但显示的唯一数据是“Model.Locations @ 421ec04eo” 为什么会发生这种情况?
针点类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.locations);
ListView listView1 = (ListView) findViewById(R.id.listView1);
ArrayList<Locations> items = new ArrayList<Locations>();
Locations sr1 = new Locations();
for (int i = 0; i < 15; i++)
{
sr1.setAdress("Blablabla");
sr1.setTitle("Home");
sr1.setDistance("200m");
items.add(sr1);
}
ArrayAdapter<Locations> adapter = new ArrayAdapter<Locations>(this,
android.R.layout.simple_list_item_multiple_choice, items);
listView1.setAdapter(adapter);
}
}
Location class
package Model;
public class Locations
{
int midlat;
int midlong;
String title;
String adress;
String distance;
public int getMidlat() {
return midlat;
}
public String getDistance() {
return distance;
}
public void setDistance(String distance) {
this.distance = distance;
}
public void setMidlat(int i) {
this.midlat = i;
}
public int getMidlong() {
return midlong;
}
public void setMidlong(int midlong) {
this.midlong = midlong;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAdress() {
return adress;
}
public void setAdress(String adress) {
this.adress = adress;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return super.toString();
}
}
locations XML.FILE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Button" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical" />
<TextView
android:id="@+id/bottomtext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:ellipsize="marquee"
android:singleLine="true" />
</RelativeLayout>