1
When I open my activity the first time, all settexts are null, the second time it works normally, what’s wrong?
Activity of the settext ..
autor = (TextView) findViewById(R.id.tv1);
editora = (TextView) findViewById(R.id.tv2);
isbntv = (TextView) findViewById(R.id.tv3);
paginas = (TextView) findViewById(R.id.tv4);
edicao = (TextView) findViewById(R.id.tv5);
ano = (TextView) findViewById(R.id.tv6);
idioma = (TextView) findViewById(R.id.tv7);
infliv = (TextView) findViewById(R.id.tv9);
imageView = (ImageView) findViewById(R.id.imageView2);
buy = (Button) findViewById(R.id.buttonbuy);
id = (TextView) findViewById(R.id.id_user);
valor = (TextView) findViewById(R.id.preço1);
Intent intent = getIntent();
mIsbn = intent.getStringExtra("mIsbn");
mDesc = intent.getStringExtra("mDesc");
mAut = intent.getStringExtra("mAut");
mVl_anun = intent.getStringExtra("mVl_anun");
mAno = intent.getStringExtra("mAno");
mImg = intent.getStringExtra("mImg");
mEdic = intent.getStringExtra("mEdic");
mIdi = intent.getStringExtra("mIdi");
mPag = intent.getStringExtra("mPag");
medicao = intent.getStringExtra("mEd");
autor.setText(mAut);
editora.setText(mEdic);
isbntv.setText(mIsbn);
paginas.setText(mPag);
edicao.setText(medicao);
ano.setText(mAno);
idioma.setText(mIdi);
infliv.setText(mDesc);
valor.setText(mVl_anun);
Activity that passes the text object ..
final ListView listViewLivros = (ListView) findViewById(R.id.lista_livros);
ListaLivroAdapter adapter = new ListaLivroAdapter(listaLivros, this);
listViewLivros.setAdapter(adapter);
listViewLivros.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
c = (TextView) view.findViewById(R.id.lista_livro_descricao);
idliv_select = c.getText().toString();
postId("http://xxxxxxxxxx/api/v2/bookdemo/_table/cad_livro?fields=qt_pag%2Cisbn%2Cano%2Cid_ed%2Cdexxxxxxxxxx_ed%2Cid_aut%2Cid_idi&filter=id_liv%20%3D%20"+idliv_select, 2);
Intent myIntent = new Intent(view.getContext(), ActivityCompra.class);
myIntent.putExtra("mIsbn",ISBN);
myIntent.putExtra("mDesc",desc);
myIntent.putExtra("mAut",autor);
myIntent.putExtra("mVl_anun",vl_anuncio);
myIntent.putExtra("mAno",ano);
myIntent.putExtra("mImg",img);
myIntent.putExtra("mEdic",edicao);
myIntent.putExtra("mIdi",idioma);
myIntent.putExtra("mPag",paglivro);
myIntent.putExtra("mEd",medicao);
startActivityForResult(myIntent, 2);
}
});
}
Post id :
private void postId(String url, int seq) {
HttpConnectionListBooks postId = new HttpConnectionListBooks(ListViewLivrosActivity.this, desc, url, seq);
postId.execute();
}
What does this postid method?
– viana
Make a get of the putExtra objects..
– Thiago
You are not making any asynchronous requests in this method?
– viana
No, I just put it under private void postid(String url, int seq) { Httpconnectionlistbooks postid = new Httpconnectionlistbooks(Listviewlivrosactivity.this, desc, url, seq); postid.execute(); }
– Thiago
If you’re using HTTP, then maybe you are. If you put Intent into this method, it’s no longer a problem. If you want to edit the question and put the content of the method, it might be easier to figure out the problem.
– viana
Edition made, sir..
– Thiago
What happens is that the method executes in the background, so the values are not assigned. The reason to run only the second time is that when you return, the values have already been loaded
– viana
Unfortunately I will have to ask what has in Httpconnectionlistbooks ... huehuhe is that there is no way to reproduce the error here because it does not have all the necessary information. = D
– viana