title: Link a TextView value to firebase database ID
body: <p>I want to link a <code>TextView</code> value to my database item ID. And then get the children that are under my database item in a <code>TextView</code>.</p>
  <p>When I scan a Barcode with the value 7, I also want the to populate a <code>TextView</code> with for example toolName from  the database Item with ID 7.</p>
  <p>I've tried and tried, but I don't know how to complete this.</p>
  <p>MainActivity:</p>
  <pre><code>public class UserMainActivity extends AppCompatActivity {
  
  TextView textusername, textworkid, textuserloggedin;
  
  Button btnalltools, qrscan;
  
  
  DatabaseReference databaseUsers, databaseTools;
  FirebaseAuth firebaseAuth;
  FirebaseUser user;
  
  String userID;
  
  String toolid;
  
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_user_main);
  
      firebaseAuth = FirebaseAuth.getInstance();
  
      databaseTools = FirebaseDatabase.getInstance(&quot;&quot;).getReference(&quot;Tools&quot;);
  
      textusername = (TextView)findViewById(R.id.tv_textusername);
      textworkid = (TextView)findViewById(R.id.tv_textuserworkid);
  
      qrscan = (Button)findViewById(R.id.btn_qrscantoolactivity);
      qrscan.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              IntentIntegrator intentIntegrator = new IntentIntegrator(UserMainActivity.this);
  
              intentIntegrator.setPrompt(&quot;For flash use volume up key&quot;);
  
              intentIntegrator.setBeepEnabled(true);
  
              intentIntegrator.setOrientationLocked(true);
  
              intentIntegrator.setCaptureActivity(Capture.class);
  
              intentIntegrator.initiateScan();
  
  
          }
      });
  
      btnalltools = (Button)findViewById(R.id.btn_alltoollist);
  
  
      btnalltools.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent1 = new Intent(UserMainActivity.this, ToollistAllActivity.class);
              startActivity(intent1);
          }
      });
  
  
  
      user = FirebaseAuth.getInstance().getCurrentUser();
      databaseUsers = FirebaseDatabase.getInstance(&quot;&quot;).getReference(&quot;Users&quot;);
      userID = user.getUid();
  
      toolid = databaseTools.getKey();
  
      databaseUsers.child(userID).addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {
  
              User userprofile = snapshot.getValue(User.class);
  
              if (userprofile != null) {
  
                  String user = userprofile.getUserName();
                  String userid = userprofile.getUserWorkId();
  
                  textusername.setText(user);
                  textworkid.setText(userid);
  
  
              }
  
  
          }
  
          @Override
          public void onCancelled(@NonNull @NotNull DatabaseError error) {
  
          }
      });
  
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
  
      if (intentResult.getContents() != null){
  
          AlertDialog.Builder builder = new AlertDialog.Builder(UserMainActivity.this);
  
  
  
          builder.setMessage(intentResult.getContents());
  
  
  
          builder.setPositiveButton(&quot;OK&quot;, new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int i) {
                  dialog.dismiss();
              }
          });
  
          builder.show();
  
  
      }else{
          Toast.makeText(getApplicationContext(), &quot;Opps&quot;, Toast.LENGTH_SHORT).show();
      }
  }
  </code></pre>
  <p>I've tried something like this:</p>
  <pre><code>
  
      IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
  
          if (intentResult.getContents() != null){
  
              TextView tv1 = dialog.findViewById(R.id.tv1);
              TextView tv2 = dialog.findViewById(R.id.tv2);
  
              tv1.setText(intentResult.getContents());
  
              databaseTools.addValueEventListener(new ValueEventListener() {
                  @Override
                  public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {
  
                      if (snapshot.hasChildren()){
  
                          if (tv1.getText().toString().equals(databaseTools)){
                              Tool tools = snapshot.getValue(Tool.class);
  
                              String tt = tools.getToolID();
  
                              tv2.setText(tt);
  
                              
                          }
  
                      }
  
  
                  }
  
                  @Override
                  public void onCancelled(@NonNull @NotNull DatabaseError error) {
  
                  }
              });
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/udLDJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/udLDJ.png" alt="enter image description here" /></a></p>