When I click Every Time Show Same Item Click What is the solution ? How can i solve this. I use Android List view and as Database use Firebase. I want To categorize List As Prioritry.
Your Help will be appreciate me.
public class BloodReqActivity extends AppCompatActivity {
ListView listview;
SearchView searchView;
FirebaseDatabase database;
ArrayList<String> list;
ArrayAdapter<String> adapter;
Blood_Request_Model blood_request_model;
ProgressDialog progressDialog;
public String key, blood, name, phone, location;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blood_req);
listview = findViewById(R.id.bloodlist);
searchView = findViewById(R.id.adsearchView);
progressDialog = new ProgressDialog(BloodReqActivity.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
blood_request_model = new Blood_Request_Model();
list = new ArrayList<>();
adapter = new ArrayAdapter<>(this, R.layout.user_info, R.id.useInfo, list);
Query query = FirebaseDatabase.getInstance().getReference("Blood_Request").orderByKey();
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
blood_request_model = ds.getValue(Blood_Request_Model.class);
key = ds.getKey();
list.add("I am " blood_request_model.getName()
". I need " blood_request_model.getHow() " " blood_request_model.getBlood() " blood at " blood_request_model.getLocation() " For my "
blood_request_model.getRelation());
}
listview.setAdapter(adapter);
progressDialog.dismiss();
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
listview.setClickable(true);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
Intent i = new Intent(BloodReqActivity.this, BloodReqUpdate.class);
i.putExtra("modelkey", key);
view.getContext().startActivity(i);
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
return false;
}
@Override
public boolean onQueryTextChange(String s) {
adapter.getFilter().filter(s);
return true;
}
});
}
} ]
Anyone please help to solve this problem. I want every time I click the different item resoponse.
CodePudding user response:
Your position lets you identify which item was clicked.
CodePudding user response:
do it like this. i.putExtra("modelkey", list.get(positin).key);
because you didn't define the position of value from array-list which are related with the position listview.
listview.setClickable(true);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
Intent i = new Intent(BloodReqActivity.this, BloodReqUpdate.class);
i.putExtra("modelkey", list.get(position).key);
view.getContext().startActivity(i);
}
});
still having problem, comment here.