title: Android Firebase cannot resolve method getRef(position) from listview
body: <p>I am a beginner to android studio! I am trying to retrieve the key(also known as the barcode for my app) from google firebase when I click on the respective listview. I would like to retrieve the respective keys and is facing a cannot resolve method error. eg. I click on the 1st ListView with the pname:"dick", i would like to retrieve only the key(barcode), 97, so that i can pass the key to another java activity so that i can retrieve the rest of the data in another activity. Hope i didnt get the logic wrong </p>
  
  <p>Here is a pic of my database:</p>
  
  <p><a href="https://i.stack.imgur.com/sibJ6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sibJ6.png" alt="enter image description here"></a></p>
  
  <p>I have tried many different code such as :<a href="https://stackoverflow.com/questions/39971476/android-firebase-cannot-resolve-method-getrefposition">Android Firebase cannot resolve method getRef(position)</a>.
  Any help would be greatly appreciated! Thanks in advance</p>
  
  <pre><code>private Button AddProduct;
  private DatabaseReference database;
  private ListView mList;
  private ArrayList&lt;String&gt; names = new ArrayList&lt;&gt;();
  private ArrayList&lt;String&gt; keys = new ArrayList&lt;&gt;();
  ArrayAdapter&lt;String&gt; arrayAdapter;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_inventory);
      AddProduct = (Button) findViewById(R.id.AddProduct);
  
  
      AddProduct.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              startActivity(new Intent(Inventory.this, AddProduct.class));
          }
      });
  
      mList = (ListView) findViewById(R.id.listView2);
  
      arrayAdapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, names);
      mList.setAdapter(arrayAdapter);
      database = FirebaseDatabase.getInstance().getReference();
      mList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int i, long l) {
             String value = (String) mList.getItemAtPosition(i);
              //Toast.makeText(Inventory.this,value,Toast.LENGTH_SHORT).show();
              Intent intent = new Intent(Inventory.this,Edit.class);
              intent.putExtra("fk",value);
              startActivity(intent);
          }
      });
  
      database.addChildEventListener(new ChildEventListener() {
          @Override
          public void onChildAdded(DataSnapshot dataSnapshot, String s) {
              arrayAdapter.clear();
              for(DataSnapshot snapshot : dataSnapshot.getChildren()){
  
                  arrayAdapter.notifyDataSetChanged();
                  String barcode = (String) snapshot.child("barcode").getValue();
                  String name = (String) snapshot.child("pname").getValue();
                  String exp = (String) snapshot.child("expiration").getValue();
                  String q = (String) snapshot.child("quantity").getValue();
                  arrayAdapter.add("Product Name: "+name+"\nExpiry Date: "+exp+ "\nQuantity: "+q+"\nBarcode: "+ barcode);
              }
  
          }
  
          @Override
          public void onChildChanged(final DataSnapshot dataSnapshot, String s) {
              String value = dataSnapshot.getValue(String.class);
              String key = dataSnapshot.getKey();
  
              int index = keys.indexOf(key);
  
              names.set(index, value);
  
              arrayAdapter.notifyDataSetChanged();
  
          }
  
          @Override
          public void onChildRemoved(DataSnapshot dataSnapshot) {
  
          }
  
          @Override
          public void onChildMoved(DataSnapshot dataSnapshot, String s) {
  
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  
  }
  </code></pre>
  
  <p>Update: I tried using either one of the code as shown below, but both shows cannot resolve method error! Any help would be greatly appreciated. Below are the codes i have tried out, but to no avail
  <a href="https://i.stack.imgur.com/C7h8M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C7h8M.png" alt="enter image description here"></a></p>