【发布时间】:2018-01-22 10:42:53
【问题描述】:
如何获取特定值 android 的选定用户的列表视图数据。
我有包含用户的列表视图。我想选择用户从包含的 Arraylist 中获取其姓名和电话。上面的代码告诉我如何在列表结果和数据中获取数据。下面的代码关于从列表中获取数据。但它显示相同的电话号码对于每个选定的用户。我想这样做:
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
【问题讨论】:
-
选中的用户是什么意思?你能详细说明一下吗?
-
请清除您的问题
-
from selected item 表示选中的用户
-
假设 ListView 的源是一个名为 myDonors 的捐赠者的 ArrayList,那么您使用
myDonor.get(position)访问捐赠者对象,假设您有一个getUser方法,并且该方法返回一个字符串,那么您可以使用String this_user = myDonor.get(position).getuser(); -
我不知道..请提出一些建议
标签: android listview arraylist