如何获取特定值android的所选用户的listview数据。
我有列表视图包含用户。我想选择用户从Arraylist获取其名称和电话。上面的代码告诉我如何获取列表中的数据结果和data.below代码从列表中获取数据。但它显示相同的电话号码对于每个选定的用户。我想这样做:
final Query query = mRef.orderByChild("blood_Group").equalTo(bloodgrp);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterable<DataSnapshot> children = dataSnapshot.getChildren();
for (DataSnapshot child : children) {
User value = child.getValue(User.class);
if(value.equals(city)){
data.add(value);
adapter.notifyDataSetChanged();
}else {
Toast.makeText(Searchview.this,"Donors not found!",Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
above code tells how i got data in lists result and data.below code about getting data from lists.but it shows same phone number for every selected user.
//List Listener
listResult.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
User user = adapter.getItem(position);
String name = (String) parent.getItemAtPosition(position);
final Dialog dialog = new Dialog(Searchview.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_user_details);
dialog.setTitle("Call Donor");
//adding text dynamically
TextView t1 = (TextView) dialog.findViewById(R.id.txtname);
TextView t2 = (TextView) dialog.findViewById(R.id.txtBldtype);
TextView t3 = (TextView) dialog.findViewById(R.id.txtphone);
TextView t4 = (TextView) dialog.findViewById(R.id.txtcity);
t1.setText(name);
t2.setText(bloodgrp);
t3.setText(phone);
t4.setText(city);
现在新的错误是: Error image
答案 0 :(得分:1)
谢谢大家最终通过实现这一目标而解决。
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterable<DataSnapshot> children = dataSnapshot.getChildren();
for (DataSnapshot child : children) {
if (dataSnapshot.getValue() != null) {
User value = child.getValue(User.class);
if(value.getCity().equals(city)){
data.add(value);
adapter.notifyDataSetChanged();
}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});