我见过其他人问过这个问题,但在我看来,我已经做了所有需要的事情,而我仍然没有让它发挥作用。我在类错误中找到名字的No setter / field。 Database 我包括了我的数据库的图片。这非常简单。
public class Restaurants {
private String name;
public Restaurants(){}
public Restaurants(String name)
{
this.name = name;
}
public String getRestaurant()
{
return name;
}
public void setRestaurant(String name)
{
this.name = name;
}
@Override
public String toString() {
return "Restaurants" +
"name" + name;
}
}
我有我的吸气剂和制定者,所以理论上应该有效。
public class RestaurantSelectionList extends Fragment {
DatabaseReference mRootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mRestReference = mRootRef.child("restaurants");
List<String>listofrest = new ArrayList<String>();
ListView restaurantListView;
ListAdapter restaurantListAdapter;
public RestaurantSelectionList(){}
@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,mRestReference) {
@Override
protected void populateView(View v, Restaurants model, int position) {
TextView restName = (TextView) v.findViewById(R.id.restname);
restName.setText(model.getRestaurant());
listofrest.add(position,model.getRestaurant());
}
};
restaurantListView.setAdapter(restaurantListAdapter);
restaurantListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getActivity(), "test", Toast.LENGTH_SHORT).show();
}
});
return view;
}
这是调用它的代码。请告诉我我错过了什么。这是持续4个小时的看法。
答案 0 :(得分:1)
请将您的模型类更改为:
public class Restaurants {
private String name;
public Restaurants(){}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
@Override
public String toString() {
return "Restaurants" + "name" + name;
}
}