gpt4 book ai didi

java - 不能使用 getRef() 吗?

转载 作者:搜寻专家 更新时间:2023-11-01 09:38:57 26 4
gpt4 key购买 nike

谁能解释为什么这是说我不能使用 getRef 获取被点击的位置?从我查过的所有内容来看,这应该有效,但由于某种原因,它无效。

public class DeleteChoiceListFragment extends Fragment {

DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mRestReference = mRootRef.child("restaurants");

List<String> listofrest = new ArrayList<String>();
ListView restaurantListView;
ListAdapter restaurantListAdapter;


public DeleteChoiceListFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.restaurant_selection_list_frag, container, false);
restaurantListView = (ListView) view.findViewById(R.id.restaurantListView);

restaurantListAdapter = new FirebaseListAdapter<Restaurants>(getActivity(), Restaurants.class, R.layout.individual_restaurant_name_nocheckbox, mRestReference) {
@Override
protected void populateView(View v, Restaurants model, final int position) {
TextView restName = (TextView) v.findViewById(R.id.restname);
restName.setText(model.getName());

listofrest.add(position, model.getName());
}
};

restaurantListView.setAdapter(restaurantListAdapter);
restaurantListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

Firebase itemtoremove = restaurantListAdapter.getRef(i);
//I get an error here saying I can't use .getRef()
itemtoremove.removeValue();


}
});
return view;

}
}

最佳答案

您已经声明 restaurantListAdapter 作为ListAdapter。即使您将 FirebaseListAdapter 对象放入该字段,您也只能访问在 ListAdapter 上定义的方法。

解决方案是同时声明该字段为 FirebaseListAdapter:

FirebaseListAdapter restaurantListAdapter;

关于java - 不能使用 getRef() 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41077476/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com