I'm a beginner at android and am working on my first app. I chose a tutorial using the google Places api and worked through it. Afterwards I decided I wanted to add a button that would choose a restaurant at random from the results. The app runs and I get no errors, testing on my galaxy tab 2. However when I click the Random button on the app, all that is displayed is the first restaurant in the list. Any help is much appreciated.
btnGetRand = (Button) findViewById(R.id.btn_get_rand);
btnGetRand.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Time t = new Time();
t.setToNow();
Random randomGenerator = new Random(t.toMillis(false));
int count = nearPlaces.results.size();
int r = randomGenerator.nextInt(count);
int id = nearPlaces.results.indexOf(r);
lv.performItemClick(lv, r, id);
}
});
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String reference = ((TextView) view.findViewById(R.id.reference))
.getText().toString();
Intent in = new Intent(getApplicationContext(),
SinglePlaceActivity.class);
in.putExtra(KEY_REFERENCE, reference);
startActivity(in);
}
});