I have an activity. I set the xml layout file via setContentView. This goes fine.
However, when I try a findViewById() or @BindView with Butter Knife I get the error that the required view was not found...
This is my activity class:
@BindView(R.id.listview_restaurants) ListView listView;
@BindView(R.id.activity_restaurant_list_image) ImageView image;
private List<Restaurant> restaurants;
private RestaurantListAdapter adapter;
private User user;
private String url;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_restaurants_list);
ButterKnife.bind(this);
this.restaurants = ((RestaurantContainer) getIntent().getSerializableExtra("restaurants")).getRestaurants();
this.user = ((UserContainer) getIntent().getSerializableExtra("user")).getUser();
this.url = getIntent().getStringExtra("url");
Picasso.with(this).load(url).into(image);
adapter = new RestaurantListAdapter(RestaurantListActivity.this, restaurants, user);
setListView();
}
private void setListView() {
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
MenuContainer menusContainer = new MenuContainer(restaurants.get(position).getMenus());
UserContainer userContainer = new UserContainer(user);
Intent intent = new Intent(RestaurantListActivity.this, MenuActivity.class);
intent.putExtra("menus", menusContainer);
intent.putExtra("url", url);
intent.putExtra("user", userContainer);
startActivity(intent);
}
});
}
}
This is my layout resource file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_restaurant_list_layout">
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:id="@+id/activity_restaurant_list_image"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:id="@+id/listview_restaurants"
android:divider="@android:color/transparent"
android:dividerHeight="10dp">
</ListView>
</LinearLayout>
Any help is appreciated!