1.I want to fetch data from the database, and then display it in the text editor for the update process. But I don't know what's wrong! the line i think i make a mistake dictionaryTerm.setText(term);
//create an internt to go to the other activity Intent intent = new Intent(SearchResultForUpdateDelete.this,AddDictionary.class); reference = database.getReference("Dictionary");//to get the reference Query toDisplay = reference.orderByChild("term_ID").equalTo(items.get(position).getTextTitle()); toDisplay.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot snapshot) { //get all values for Database String term_id = snapshot.child(items.get(position).getTextTitle()).child("term_ID").getValue(String.class); String type = snapshot.child(items.get(position).getTextTitle()).child("type").getValue(String.class); String term = snapshot.child(items.get(position).getTextTitle()).child("term").getValue(String.class); intent.putExtra("term_id",term_id); intent.putExtra("type",type); intent.putExtra("term",term); } @Override public void onCancelled(@NonNull DatabaseError error) { } }); startActivity(intent); //in the second activity private EditText dictionaryTerm, dictionaryType; Bundle bundle = getIntent().getExtras(); if (bundle != null) { String term_id = bundle.getString("term_id"); String type = bundle.getString("type"); String term = bundle.getString("term"); if(!term.isEmpty() && !term_id.isEmpty() && !type.isEmpty()){ dictionaryTerm.setText(term); } } https://stackoverflow.com/questions/66594086/how-to-set-a-passing-value-in-edittext-in-android-studio March 12, 2021 at 12:11PM
没有评论:
发表评论