Android 将ArrayList传递给其他活动时出现问题

Android 将ArrayList传递给其他活动时出现问题,android,listview,android-activity,arraylist,parameters,Android,Listview,Android Activity,Arraylist,Parameters,晚上好,我在将ListView活动传递给另一个活动时遇到问题。传递给另一方的活动代码是以下名为filterarimoveis.class的代码: for (int i = 0; i < jsonArray.length(); i++) { Imovel imv = new Imovel(); JSONObject child = jsonArray.getJSONObject(i);

晚上好,我在将ListView活动传递给另一个活动时遇到问题。传递给另一方的活动代码是以下名为filterarimoveis.class的代码:

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);
}
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());
}
for(int i=0;i
从ListView继承的类如下所示,称为detalhesismoveis.class:

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);
}
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());
}
private ListView lvImoveis;
ArrayList listaImoveis;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u detalhes\u imovis);
listaImoveis=(ArrayList)getIntent().getSerializableExtra(“lista”);
lvImoveis=(ListView)findViewById(R.id.lvImoveis);
试一试{
ArrayAdapter adpImovel=新的ArrayAdapter(detalhesismoveis.this,android.R.layout.simple\u list\u item\u 1,listaImoveis);
lvImoveis.setAdapter(adpImovel);
//Log.v(“LISTAiMOVEIS”,“ELEMENTOS DA LISTA:+LISTAiMOVEIS.get(0.getdescripcao().toString());
}捕获(例外e){
Log.v(“logs”,“异常列表引起的错误:+e.toString());
}

}我们不应该对ArrayList使用
putExtra()
,而应该使用
putStringArrayListExtra()
例如:
公共无效carregar(ArrayList listaImovel){
意向意向=新意向(此为detalhesismoveis.class);
意图。putStringArrayListExtra(“lista”,listaImovel);

并且在detalhesismoveis.class中获取如下数组列表:
listaImoveis=getIntent().getStringArrayListExtra(“lista”);
u可以:

    getIntent().putParcelableArrayListExtra(listaImovel)
      Imovel need to implment Parcelable 
你可以看一些关于包裹的东西; 或: AActvt Put list int应用程序或静态变量;
BACTVTVT从应用程序或静态变量获取列表;

但是对于intent.putStringArrayListExtra,它需要一个String类型的数组。我不知道为什么要使用
,您在
listaImovel
中添加的值只是字符串。因此您可以将其作为字符串本身传递。我发现,错误在返回JSON对象的webservice中。