androidlistviewandroid-intentadaptergetview

GetView + Intent Param Object Error


I have this problem now: java.lang.RuntimeException: Parcelable encountered IOException writing serializable object .. Class Filho implements serializable. How to solve?

public View getView(int position, View view, ViewGroup parent)
{
    final Filho filhoPosition = this.listaFilhos.get(position);
    view = LayoutInflater.from(this.context).inflate(R.layout.lista_filho,null);

    TextView textViewNomeFilho = (TextView) view.findViewById(R.id.textViewNomeFilho);
    TextView textViewTelefoneFilho = (TextView) view.findViewById(R.id.textViewTelefoneFilho);
    ImageView imageViewFotoFilho = (ImageView)  view.findViewById(R.id.imageViewFotoFilho);

    textViewNomeFilho.setText(filhoPosition.getNome());
    textViewTelefoneFilho.setText(filhoPosition.getTelefone());
    imageViewFotoFilho.setImageBitmap(filhoPosition.getFoto());

    final ImageButton imageButtonConfigFilho = (ImageButton) view.findViewById(R.id.imageButtonConfigFilho);
    imageButtonConfigFilho.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){

            filho = new Filho(filhoPosition.getIdFilho(),filhoPosition.getNome(),filhoPosition.getTelefone(),filhoPosition.getFoto(),filhoPosition.getLoginConfig());

            Intent it = new Intent(context, CadastrarFilhoActivity.class);
            it.putExtra("filho",filho);
            context.startActivity(it);
        }
    });
    return view;
}

Solution

  • Make Filho class implements Serializable .It is a common problem

    That is go to Filho class and implement Serializable

    public class Filho class implements Serializable
    

    Edit

    Use intent like this you are using putExtra()

    Intent it = new Intent(context, CadastrarFilhoActivity.class);
    Bundle bundle = new Bundle();
    bundle.putSerializable("filho",filho);
    it.putExtras(bundle);
    

    and get by this in CadastrarFilhoActivity.class

    Intent intent = this.getIntent();
    Bundle bundle = intent.getExtras();
    Filho filho=(Filho)bundle.getSerializable("filho");