0

The thing is ... In an Activity I fill some fields to popularem one ListView to be loaded into another Acitivity , has tried to show it in the same Activity and works, the error happens when I try to show it in another Acitivity , I believe It has to do with the Context.

The Activity used to populate the parameters and that works if the list is shown it is called FiltrarImoveis where this step only in the Context of ArrayAdapter .

The Activity giving problem is called DetalhesImoveis , try to pass this , DetalhesImoveis.this and keeps giving error ... Here is the Activity section of code that is giving error:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ArrayList<String> listaImoveis = new ArrayList<String>();
    listaImoveis.add("foo");
    listaImoveis.add("bar");
    ArrayAdapter<String> adpImovel = new ArrayAdapter<String>(DetalhesImoveis.this,android.R.layout.simple_list_item_1, listaImoveis);
    lvImoveis.setAdapter(adpImovel);
}

Full code DetalhesImoveis.class:

package com.example.dhjeferson.testemenu;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;

public class DetalhesImoveis extends AppCompatActivity {

    private ListView lvImoveis;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ArrayList<String> listaImoveis = new ArrayList<String>();
        /*setContentView(R.layout.activity_detalhes_imoveis);
        TextView showParsedJSON = (TextView) findViewById(R.id.json);

        Intent intent = getIntent();
        String output = intent.getStringExtra("output");
        showParsedJSON.setText(output);*/
        /*FiltrarImoveis filtrarImoveis = new FiltrarImoveis();
        listaImoveis = filtrarImoveis.retornaLista();*/
        lvImoveis = (ListView)findViewById(R.id.lvImoveis);

        Imovel imv = new Imovel();
        imv.setGenero("Genero");
        imv.setFinalidade("Finalidade");
        imv.setTipo("Tipo");
        imv.setValor("Valor");
        listaImoveis.add("foo");
        listaImoveis.add("bar");
        try {
            ArrayAdapter<String> adpImovel = new ArrayAdapter<String>(DetalhesImoveis.this, android.R.layout.simple_list_item_1, listaImoveis);

            lvImoveis.setAdapter(adpImovel);
        }catch(Exception e){
            Log.v("logs","ERROR CAUSED BY THE EXCEPTION LIST: "+e.getStackTrace().toString());
        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_detalhes_imoveis, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
user370305
  • 108,599
  • 23
  • 164
  • 151

0 Answers0