【发布时间】:2018-04-22 05:49:16
【问题描述】:
我有两个活动和一个模型类。在活动 A
我有城市命名为cityA,cityB,cityC等。
在第二个活动中,我展示了 7 个 TextView
根据城市名称的详细信息。
尝试做intent.putExtra 但崩溃了。请告诉
如果我错过了什么。
注意:如果我点击 cityA 详细信息应该只有 来自A市。
活动A的代码
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
CityTable table1 = (CityTable)listView.getItemAtPosition(i);
String toolbartitle = table1.getAreaName(); //for toolbar
String population = table1.getPopulation_2015();
String established = table1.getYearEstablished();
Intent intent = new Intent(getApplicationContext(), ActivityB.class);
intent.putExtra("toolbartitle",toolbartitle);
intent.putExtra("population",population);
intent.putExtra("established",established);
startActivity(intent);
活动B代码
List<CityTable> tablecity= new ArrayList<>();
tablecity.addAll((List<CityTable>) result);
for (final CityTable city : tablecity){
String toolbartitle = getIntent().getExtras().getString("toolbartitle");
String population = getIntent().getExtras().getString("population");
String established = getIntent().getExtras().getString("established");
textview1 = (TextView) findViewById(R.id.textview1);
textview2 = (TextView) findViewById(R.id.textView3);
textview3 = (TextView) findViewById(R.id.textView4);
textview1.setText(population);
and so on....
我不知道..我缺少位置或其他东西,但是崩溃了
崩溃日志
java.lang.ClassCastException: java.lang.String cannot be cast to com.project_android.Citytable
【问题讨论】:
-
嗨@Vivek,请提供您在 ListView 中使用的列表类型。
-
最终列表
citytable= new ArrayList(); -
请提供您的适配器代码。
标签: listview android-intent classcastexception