Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7830315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:10:54+00:00 2026-06-02T11:10:54+00:00

I Have a framgment that show a list in a Dialog. In the Dialog

  • 0

I Have a framgment that show a list in a Dialog. In the Dialog I have a clickListener that open one Activity. This Activity not is the FragmentActivity.

When I’m try get this values, hes come null. Help…

My Fragment class

package br.com.test.fragments;

import java.util.List;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import br.com.test.controllers.CorredoresController;
import br.com.test.R;
import br.com.test.SPAndroidConstantes;
import br.com.test.activity.ListaCorredoresActivity;
import br.com.test.adapter.ListaCorredoresAdapter;
import br.com.test.util.Utilities;
import br.com.spparser.beans.corredores.NomeCorredor;
import br.com.spparser.exception.SPException;

public class PesquisaFragment extends Fragment implements SPAndroidConstantes,     OnItemClickListener {

private ProgressDialog dialog;
private Handler handler = new Handler();
List<NomeCorredor> p;
private Exception ex;
private ListaCorredoresAdapter lcAdapter;


public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //fillAdMod();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance)
{
    LinearLayout linearLayout = (LinearLayout) inflater.inflate(R.layout.pesquisa, container, false);
    EditText edit = (EditText) linearLayout.findViewById(R.id.editPesquisa);
    Button btnLinhas = (Button) linearLayout.findViewById(R.id.btnLinhas);
    Button btnPontos = (Button) linearLayout.findViewById(R.id.btnPontos);

    Button btnCorredor = (Button)linearLayout.findViewById(R.id.btnCorredores);
    btnCorredor.setOnClickListener(buttonCorredorListener);

    return linearLayout;
}

private void downloadInfo() {
    new Thread() {
        @Override
        public void run() {
            try {
                p = CorredoresController.getInstance().getCorredores();
                atualizaTela();
            } catch (Exception e) {
                ex = e;
                atualizaTelaExcecao();
            }
        }
    }.start();
}

/**
 * Thread para fechar dialog e apresentar informações
 */
private void atualizaTela() {
    handler.post(new Runnable() {
        @Override
        public void run() {
            dialog.dismiss();
            preencheTela();
        }
    });
}

/**
 * Thread para fechar dialog e apresentar exceção
 */
private void atualizaTelaExcecao() {
    handler.post(new Runnable() {
        @Override
        public void run() {
            dialog.dismiss();
            preencheTelaExcecao();
        }
    });
}

/**
 * Preenche informações da tela
 */
private void preencheTela() {
    // Criando e setando o adaptador personalizado para Lista 1
    lcAdapter = new ListaCorredoresAdapter(this.getActivity(),
            p);

    if (p.size() == 0) {
        Toast.makeText(PesquisaFragment.this.getActivity(), MSG_SEM_CORREDOR,
                MSG_TIME_MILIS).show();
        //this.getActivity().finish();
    }

    Dialog dialogCorredor = new Dialog(PesquisaFragment.this.getActivity());
    dialogCorredor.setTitle("Selecione o corredor");
    LayoutInflater li = (LayoutInflater) PesquisaFragment.this.getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = li.inflate(R.layout.teste_list, null, false);
    ListView lista = (ListView) v.findViewById(R.id.listTeste);
    lista.setAdapter(lcAdapter);
    dialogCorredor.setContentView(v);
    dialogCorredor.setCancelable(true);
    dialogCorredor.show();

    lista.setOnItemClickListener(this);
}

/**
 * Apresenta mensagem em caso de exceção
 */
private void preencheTelaExcecao() {
    if (ex instanceof SPException) {
        Toast.makeText(PesquisaFragment.this.getActivity(),
                ((SPException) ex).getMessage(), MSG_TIME_MILIS).show();
        //PesquisaFragment.this.getActivity().finish();
    } else {
        Toast.makeText(PesquisaFragment.this.getActivity(),
                getString(R.string.msg_ErroSistema), MSG_TIME_MILIS).show();
        //PesquisaFragment.this.getActivity().finish();
    }
}

private OnClickListener buttonCorredorListener = new OnClickListener() {

    @Override
    public void onClick(View arg0) {
        dialog = ProgressDialog.show(PesquisaFragment.this.getActivity(), "",
                "Aguarde...", true);
        if (!Utilities.chkStatus(PesquisaFragment.this.getActivity()))
            return;

        downloadInfo();
    }
};

@Override
public void onItemClick(AdapterView parent, View v, int position, long id) {
    if (!Utilities.chkStatus(PesquisaFragment.this.getActivity()))
        return;
    NomeCorredor corredor = (NomeCorredor) parent.getAdapter().getItem(position);


    Bundle bundle = new Bundle();
    bundle.putInt("Cod", corredor.getCodigoCorredor());
    bundle.putString("Desc", corredor.getNomeCorredor());

    Intent listaCorreIntent = new Intent(PesquisaFragment.this.getActivity(), ListaCorredoresActivity.class);
    listaCorreIntent.putExtras(bundle);
    startActivity(listaCorreIntent);
}

}

My activity class

package br.com.test.activity;

import br.com.test.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class ListaCorredoresActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.item_corredor);
    String texto = String.valueOf(savedInstanceState.getInt("Cod")) + " - " + savedInstanceState.getString("Desc");
    Toast.makeText(this, texto, Toast.LENGTH_LONG);
}

When I try get the
savedInstanceState.getInt(“Cod”)
His come null

Why???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:10:55+00:00Added an answer on June 2, 2026 at 11:10 am

    Bundle generally use for passing data between various Activities. It depends on you what type of values you want to pass but bundle can hold all types of values and pass to the new activity. you can also find more info on android-using-bundle-for-sharing-variables and Passing-Bundles-Around-Activities

    String texto = String.valueOf(savedInstanceState.getInt("Cod")) + " - " + savedInstanceState.getString("Desc");
    

    replace the above line with this line

     Bundle extras = intent.getExtras();
     String texto  = extras.getInt("Cod")+"-"+extras.getString("Desc");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in an Activity that starts a dialog for a
I have an Activity that calls setContentView with this XML: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent
Using this sample : I have make my own Fragment that holds tabhost and
I'm using Android-support-v4 I have a PagerAdapter that displays a list fragment in each
I have this very simple (yet big) code that doesn't work. The triangle doesn't
I have an Activity that manages about four fragments. The activity decides when to
I'm using THIS plugin to show n strings that scroll up every 5 seconds.
I have an Activity that has 2 fragments. Both are ListFragments and both contribute
I have an activity with in which there is a async task that will
What does this mean? I have been fighting with this ListView that I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.