请帮助。 我想获得描述和用户的值。 这是我的代码;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab1,container,false);
list = (ListView) view.findViewById(R.id.mylistview);
final DatabaseReference rootRef =
FirebaseDatabase.getInstance().getReference();
final DatabaseReference errandsRef = rootRef.child("Errands");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
for(final DataSnapshot ds : dataSnapshot.getChildren()) {
final String Errand = ds.child("Errand").getValue(String.class);
ll.add(Errand);
ListAdapter adp = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,ll);
//ll.clear();
list.setAdapter(adp);
list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = (String) list.getItemAtPosition(position);
请帮助。我应该在onItemClick中放入哪些代码来获取用户以及已点击的项目的代码?
答案 0 :(得分:1)
您可以使用.orderByChild()
和.equalTo()
。您知道点击项目的Errand
:
String item = (String) list.getItemAtPosition(position);
FirebaseDatabase.getInstance().getReference().child("Errands").orderByChild("Errand").equalTo(item).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//this dataSnapshot is the your object you want
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});