我有一个奇怪的问题。这是代码:
public class TaxiDetails extends Activity{
ArrayList<Bus> listBus = new ArrayList<Bus>();
ArrayList<Taxi> listTaxi = new ArrayList<Taxi>();
TextView detalji, title;
ImageView backBtn;
String strType;
StringBuilder builder = new StringBuilder();
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.numbers_details);
detalji = (TextView) findViewById(R.id.txtNumbDetails);
title = (TextView) findViewById(R.id.txtTitleNumbers);
detalji.setTypeface(Typeface.DEFAULT_BOLD);
Typeface TF = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Black.ttf");
backBtn = (ImageView) findViewById(R.id.backBtn);
title.setTypeface(TF);
Intent in = getIntent();
strType = in.getStringExtra("type");
if (strType.equals("TAXI")){
listTaxi = (ArrayList<Taxi>) in.getSerializableExtra("TAXI");
title.setText("Taxi");
} else if (strType.equals("BUS")){
listBus = (ArrayList<Bus>) in.getSerializableExtra("BUS");
title.setText("BUS");
}
if (listBus != null) {
for (int i = 0; i < listBus.size(); i++) {
builder = new StringBuilder();
String naslov = listBus.get(i).getTitle();
String opis = listBus.get(i).getDescription();
builder.append(naslov);
builder.append("\n");
builder.append(Html.fromHtml(opis));
builder.append("\n");
}
}
if (listTaxi != null) {
for (int i = 0; i < listTaxi.size(); i++) {
builder = new StringBuilder();
String naslov = listTaxi.get(i).getTitle();
String opis = listTaxi.get(i).getDescription();
builder.append(naslov);
builder.append("\n");
builder.append(Html.fromHtml(opis));
builder.append("\n");
}
}
detalji.setText(builder.toString().trim());
}
}
我从以前的活动中传递了一个数组。Taxi 或 Bus 对象的数组,具体取决于用户选择的对象。但是,对于出租车来说,这非常有效。对于 Bus,它只显示数组的最后一个对象,即使调试器显示 listBus 包含 2 个对象。我使用相同的 listBus iN Google Map 活动,它可以显示所有对象的位置,为什么它在这里不起作用?