我正在记录以下字段作为输出:
I/System.out: getLongitude 4.745929
I/System.out: getStreet Laat 199
I/System.out: getLatitude 52.630753
I/System.out: getCity Alkmaar
I/System.out: getZipCode 1811 EG
I/System.out: getName SUBWAY® Alkmaar
I/System.out: getFacebookID 180894875290925
但我想在下面的ListView
输出,你可以看到我ListView
目前的样子截图:
链接到屏幕截图:http://i.imgur.com/YfWMjkG.png
下面你可以看到我尝试过的内容:
AllStores.java:
Iterator it = subprises.body().iterator();
List<Store> subprisesList = new ArrayList<>();
int i = 0;
while(it.hasNext()) {
i++;
Store store = (Store) it.next();
System.out.println("getLongitude "+store.getLongitude());
System.out.println("getStreet "+store.getStreet());
System.out.println("getLatitude "+store.getLatitude());
System.out.println("getCity "+store.getCity());
System.out.println("getZipCode "+store.getZipCode());
System.out.println("getName "+store.getName());
System.out.println("getFacebookID "+store.getFacebookID());
System.out.println("next store");
subprisesList.add(store);
}
StoreArrayAdapter stringArrayAdapter = new StoreArrayAdapter(
getApplicationContext(),
R.layout.listview_item_row,
subprisesList);
lv.setAdapter(stringArrayAdapter);
编辑:我已更改了StoreArrayAdapter类
StoreArrayAdapter class which lives inside AllStores.java:
private class StoreArrayAdapter extends ArrayAdapter<Store> {
public StoreArrayAdapter(Context context, int textViewResourceId, List<Store> stores) {
super(context, textViewResourceId, stores);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View storeView = convertView;
if (convertView == null) {
// inflate your list view here
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
storeView = inflater.inflate(R.layout.listview_item_row, parent, false);
}
Store store = getItem(position);
// use findViewById() to get the TextViews
TextView name = (TextView)storeView.findViewById(R.id.txtName);
// call setText using the values from store
name.setText(store.getName());
return convertView;
}
}
此次,我想向您展示我的观点以及名为Store
的模型。
activity_all_stores.xml:
链接到代码:http://pastebin.com/6eiUyPKU
listview_item_row.xml:
链接到代码:http://pastebin.com/CGSVf2Uq
Store.java: