0
Good Morning Everyone I have a Fragment containing a listview where I list the data coming from a webservice. In the onclick method I have the following code where I pass some values to another Activity according to the code below.
ltwPacote.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long
id) {
JsonObject obj = (JsonObject) parent.getItemAtPosition(position);
String codigo = obj.get("i_cdpacote").getAsString();
String descricaopacote = obj.get("c_descricao").getAsString();
String preco = obj.get("n_precopacote").getAsString();
String regra = obj.get("c_regra").getAsString();
Intent intent = new Intent(getActivity(), VisualizaPacote.class);
intent.putExtra("i_cdpacote", codigo);
intent.putExtra("c_descricao", descricaopacote);
intent.putExtra("n_precopacote", preco);
intent.putExtra("c_regra", regra);
startActivity(intent);
In my Activity Visualizapackage I have the following code:
Intent intent = getIntent();
String descricao = intent.getStringExtra("descricaopacote");
String preco = intent.getStringExtra("preco");
String regra =intent.getStringExtra("regra");
TextView txtdescricaopacote = (TextView) findViewById(R.id.txtPacote);
txtdescricaopacote.setText(descricao);
TextView txtpreco = (TextView) findViewById(R.id.txtPreco);
txtpreco.setText(preco);
TextView txtregra = (TextView) findViewById(R.id.txtRegra);
txtregra.setText(regra);
It turns out that when clicking on the item in the list to view the details these parameters are not appearing in the Preview Toolpack. If anyone could guide me, I’d appreciate it.
Try it like this: String Description = Intent.getStringExtra("c_description") .....
– Reginaldo Rigo
Thanks for the help, it worked.
– Henrique Augusto Vieira