我刚刚开始学习android和java。我想通过利用Android Studio的自动生成功能使用底部导航和recyclerview制作示例(因此片段中使用了recyclerview)。
在我更改项目的类(从自动生成的DummyContent到我制作的类)之前,一切工作都很顺利。 但是更改类后,它在屏幕上不会显示任何项目。
这是什么问题?这是我的代码。
StoreFragment.java
public interface OnListFragmentInteractionListener {
void onListFragmentInteraction(Store.StoreInfo item);
}
MainActivity.java
@Override
public void onListFragmentInteraction(Store.StoreInfo item){
}
MyStoreRecyclerViewAdater.java
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.mItem = mValues.get(position);
holder.mNameView.setText(mValues.get(position).name);
holder.mFeatureView.setText(mValues.get(position).feature);
holder.mAddressView.setText(mValues.get(position).address);
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != mListener) {
//Click Event
mListener.onListFragmentInteraction(holder.mItem);
}
}
});
}
...
public class ViewHolder extends RecyclerView.ViewHolder {
public final View mView;
public final TextView mNameView;
public final TextView mFeatureView;
public final TextView mAddressView;
public Store.StoreInfo mItem;
public ViewHolder(View view) {
super(view);
mView = view;
mNameView = (TextView) view.findViewById(R.id.item_name);
mFeatureView = (TextView) view.findViewById(R.id.item_feature);
mAddressView = (TextView) view.findViewById(R.id.item_address);
}
Store.java
public class Store {
public static final List<StoreInfo> items = new ArrayList<StoreInfo>();
public Store(){
addItem(new StoreInfo("name0","feature0","address0"));
addItem(new StoreInfo("name1", "feature1", "address1"));
addItem(new StoreInfo("name2", "feature2","address2"));
}
private static void addItem(StoreInfo item){
items.add(item);
}
public static class StoreInfo{
public String name;
public String feature;
public String address;
public StoreInfo(String name, String feature, String address) {
this.name = name;
this.feature = feature;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFeature() {
return feature;
}
public void setFeature(String feature) {
this.feature = feature;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
}