【发布时间】:2017-11-30 07:57:34
【问题描述】:
我希望我的孩子数据在我更改数据时实时更新。我是Java编程新手。错误是当我尝试使用新的子数据设置我的列表数组列表时,错误的第二个参数出现错误。以下是我的代码...感谢任何帮助,提前致谢。
public class OverallResultFragment extends Fragment {
private static final String TAG = "OverallResultFragment";
private ArrayList<Booth> list = new ArrayList<>();;
private ArrayList<Booth> mkeys = new ArrayList<>();
ProductListAdapter adapter = null;
private Firebase mRef;
ListView gridView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Firebase.setAndroidContext(this.getContext());
View view = inflater.inflate(R.layout.activity_votingresult, container, false);
mRef = new Firebase("https://myfb.firebaseio.com/myfb");
gridView = (ListView) view.findViewById(R.id.gridView);
adapter = new ProductListAdapter(this.getContext(), R.layout.list_product_item, list);
gridView.setAdapter(adapter);
com.firebase.client.Query Queryref = mRef.orderByValue();
Queryref.addChildEventListener(new com.firebase.client.ChildEventListener() {
@Override
public void onChildAdded(com.firebase.client.DataSnapshot dataSnapshot, String s) {
String value = dataSnapshot.getValue(String.class);
String boothname = dataSnapshot.getKey();
list.add(new Booth(boothname, value));
mkeys.add(new Booth(boothname));
adapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(com.firebase.client.DataSnapshot dataSnapshot, String s) {
String value = dataSnapshot.getValue(String.class);
String boothname = dataSnapshot.getKey();
int index = mkeys.indexOf(boothname);
list.set(index, value);//error on "value" -> wrong 2nd argument.
adapter.notifyDataSetChanged();
}
}
这是我的 Booth 课:
public class Booth {
String rating;
String Boothname;
int index;
public Booth(String boothname, String Rating){
this.Boothname = boothname;
this.rating= Rating;
}
public String getBoothName(){
return Boothname;
}
public void setProductId(String boothname){
this.Boothname = boothname;
}
public String getRating(){
return rating;
}
public void setRating(String rating){
this.rating = rating;
}
}
【问题讨论】:
标签: android listview firebase firebase-realtime-database