晚上好,我無法將ListView和Activity傳遞給另一個Activity。其傳遞給其他活動代碼是下面稱爲FiltrarImoveis.class:麻煩傳遞ArrayList到另一個活動
for (int i = 0; i < jsonArray.length(); i++) {
Imovel imv = new Imovel();
JSONObject child = jsonArray.getJSONObject(i);
String finalidade=child.getString("finalidadeImovel");
String tipo = child.getString("tipoImovel");
String genero = child.getString("generoImovel");
String descricao = child.getString("descricaoImovel");
String responsavel = child.getString("responsavelImovel");
String telefoneResponsavel = child.getString("telefoneResponsavel");
String situacaoImovel = child.getString("situacaoImovel");
String valor = child.getString("valor");
imv.setFinalidade(finalidade);
imv.setTipo(tipo);
imv.setGenero(genero);
imv.setDescricao(descricao);
imv.setResponsavel(responsavel);
imv.setTelefoneResponsavel(telefoneResponsavel);
imv.setSituacao(situacaoImovel);
imv.setValor(valor);
listaImovel.add(imv);
}
} catch (JSONException e) {
e.printStackTrace();
}
//showParsedJSON.setText(output);
carregar(listaImovel);
}
}
}
public void carregar(ArrayList<Imovel> listaImovel){
Intent intent = new Intent(this,DetalhesImoveis.class);
intent.putExtra("lista",listaImovel);
startActivity(intent);
}
從ListView中繼承的類是下文中,稱之爲DetalhesImoveis.class:
private ListView lvImoveis;
ArrayList<Imovel> listaImoveis;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detalhes_imoveis);
listaImoveis = (ArrayList<Imovel>) getIntent().getSerializableExtra("lista");
lvImoveis = (ListView)findViewById(R.id.lvImoveis);
try {
ArrayAdapter<Imovel> adpImovel = new ArrayAdapter<Imovel>(DetalhesImoveis.this, android.R.layout.simple_list_item_1, listaImoveis);
lvImoveis.setAdapter(adpImovel);
//Log.v("LISTAiMOVEIS", "ELEMENTOS DA LISTA: " +listaImoveis.get(0).getDescricao().toString());
}catch(Exception e){
Log.v("logs","ERROR CAUSED BY THE EXCEPTION LIST: "+e.toString());
}
}
但intent.putStringArrayListExtra,它需要一個字符串數組字符串 –
我不知道你爲什麼使用'',你在'listaImovel'中添加的值只是字符串。所以你可以將它作爲String傳遞。 –
GIRIDHARAN
我發現,錯誤是在webservice中返回JSON對象。 –