2016-12-08 6 views
1

他の人がこの質問をしているのを見たことがありますが、私は必要なすべてのことをやっているようです。クラスエラーで見つかった名前のためのNoセッター/フィールドを取得しています。 Database 私のデータベースの写真を掲載しました。それは信じられないほど簡単です。Firebaseのクラスで見つかったsetter/fieldはありません

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時間続いています。

答えて

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; 
    } 
} 
+0

はありがとうございました。私はそれを見たに違いない – Hunter

関連する問題