简体   繁体   中英

Listview wont show stackmob query list

Hello im trying to get stackmob to query a items to a listview everything is working except the result list appearing in the listview i have tried search all over the internet and have found nothing that has worked. here is my code when i use Log.i("Tagg", result.get(0).getAddress()); it works perfectly and displays the address so i dont know why it wont show up in the listview?

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 public class ListAdapter extends 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;
}

}

I work for StackMob.

Your activity subclasses ListActivity, which requires that your layout contain a ListView with the id @android:id/list. It looks like your ListView is called resultslist; try changing the name.

For more information, check out this tutorial on ListViews . ListActivity is covered in section 3.

Cheers,

Carl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM