我想在 TextView 中显示存储在 ArrayList 中的值,这样当应用程序运行时,名称就会与其他详细信息一起出现在 TextView 中。
我可以从 ArrayList 读取值并将它们显示在 logcat 中。它们也显示在 ListView 上,但我无法让它们显示在 TextView 上。
private ArrayList<Country> countries;
private ArrayList<Country> countries;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lvCountries = findViewById(R.id.main_activity_lv_countries);
tvDetails = findViewById(R.id.activity_country_details);
lvCountries.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//create an intent for the FlagDisplayActivity
Intent intentBundle = new Intent(MainActivity.this, FlagDisplayActivity.class);
Bundle bundleName = new Bundle();
//put arg2 as an extra in the intent. arg2 represents the item clicked on
//e.g arg2 will be 0 if the first item was clicked
intentBundle.putExtra(countries.get(position).getName(), countries.get(position).getFlagImageResourceId());
//start the activity
startActivityForResult(intentBundle, DELETE_REQUEST);
}
});
信息不会显示在 TextView 中。
当年话下
相关分类