您好我试图让stackmob查询项目到列表视图一切正常,除了列表视图中出现的结果列表我尝试在互联网上搜索并找不到任何有效的方法。 当我使用Log.i(“Tagg”,result.get(0).getAddress())时,这是我的代码;它完美地工作并显示地址所以我不知道为什么它不会出现在列表视图中?
ResultsActivity.java
public class ResultsActivity extends ListActivity {
double lon;
double lat;
ListAdapter adapter;
List<RRData> RestR;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setListAdapter(new ListAdapter(this, R.layout.resultslist, null));
setListAdapter(adapter);
Bundle extras = getIntent().getExtras();
lon = extras.getDouble("Longitude");
lat = extras.getDouble("Latitude");
StackMobGeoPoint sarea = new StackMobGeoPoint(lon, lat);
StackMobQuery q = new StackMobQuery().fieldIsNearWithinMi("location", sarea, 1110.0); //(lon, lat), distance (miles)
RRData.query(RRData.class, q, new StackMobQueryCallback<RRData>() {
@Override
public void success(List<RRData> result) {
Log.i("Tagg", result.get(0).getAddress());
//adapter = new ListAdapter(ResultsActivity.this, R.layout.resultslist, result);
RestR = result;
ListAdapter adapter = new ListAdapter(ResultsActivity.this, R.layout.resultslist, RestR);
setListAdapter(adapter);
adapter.notifyDataSetChanged();
}
@Override
public void failure(StackMobException e) {
Log.i("TagError", e.getLocalizedMessage());
}
});
setContentView(R.layout.activity_results);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_results, menu);
return true;
}
}
RRData.java
public class RRData extends StackMobModel {
private String name;
private StackMobGeoPoint location;
private String Address;
private String UserName;
public RRData(String name, StackMobGeoPoint location,String Address) {
super(RRData.class);
this.name = name;
this.location = location;
this.Address = Address;
}
public String getName() {
return name;
}
public String getAddress(){
return Address;
}
public void setName(String name){
this.name = name;
}
public void setAddress(String address){
this.Address = address;
}
public void setLocation(StackMobGeoPoint location){
this.location = location;
}
public StackMobGeoPoint getLocation() {
return location;
}
}
ListAdapter.java 公共类ListAdapter扩展ArrayAdapter {
public ListAdapter(Context context, int textViewResourceId, List<RRData> tasks) {
super(context, textViewResourceId, tasks);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.resultslist, null);
}
RRData task = getItem(position);
if (task != null) {
((TextView) v.findViewById(R.id.title)).setText(task.getName());
((TextView) v.findViewById(R.id.address)).setText(task.getAddress());
((TextView) v.findViewById(R.id.distance)).setText(task.getLocation().getQueryDistanceRadians().toString());
this.notifyDataSetChanged();
}
return v;
}
}
答案 0 :(得分:1)
我为StackMob工作。
您的活动是ListActivity的子类,它要求您的布局包含一个ID为@android:id / list的ListView。看起来你的ListView被称为resultslist;尝试更改名称。
有关详细信息,请check out this tutorial on ListViews。 ListActivity将在第3节中介绍。
干杯,
卡尔