私はアンドロイドの初心者で、最初のアプリに取り組んでいます。Google Places API を使用するチュートリアルを選択し、それを実行しました。その後、結果からレストランをランダムに選択するボタンを追加したいと考えました。アプリは実行され、エラーは発生せず、galaxy タブ 2 でテストします。ただし、アプリの [ランダム] ボタンをクリックすると、リストの最初のレストランだけが表示されます。どんな助けでも大歓迎です。
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);
}
});