【问题标题】:My Recyclerview layout is not showing after not working for quite some time. It shows relayout returned我的 Recyclerview 布局在很长一段时间没有工作后没有显示。它显示重新布局返回
【发布时间】:2020-06-19 13:43:36
【问题描述】:

上次我在开发我的应用程序时,它按预期运行良好。一个月不工作后,它不会像我上次工作时那样弹出布局。当我点击按钮时,它只会导致一个空白页面

适配器

public class RestaurantAdapter extends FirebaseRecyclerAdapter<RestaurantDetails,RestaurantAdapter.RestaurantViewHolder> {


public RestaurantAdapter(@NonNull FirebaseRecyclerOptions<RestaurantDetails> options) {
    super(options);
}

FirebaseRecyclerOptions<RestaurantDetails> options =
        new FirebaseRecyclerOptions.Builder<RestaurantDetails>()
                .setQuery(FirebaseDatabase.getInstance().getReference().child("Restaurant").child("Info"), RestaurantDetails.class)
                .build();



@Override
protected void onBindViewHolder(@NonNull RestaurantViewHolder holder, final int position, @NonNull final RestaurantDetails details) {

    holder.restaurant_Name.setText(details.getName());
    holder.restaurant_Category.setText(details.getCategory());
    holder.restaurant_Location.setText(details.getLocation());

    Picasso.get().load(details.getImage()).into(holder.restaurant_Image);


    holder.itemView.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view){
            String post_key = getRef(position).getKey();

            Intent intent = new Intent(view.getContext(), RestaurantInfoActivity.class);
            intent.putExtra("post_key", post_key);
            view.getContext().startActivity(intent);

        }
    });
}

@NonNull
@Override
public RestaurantViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view =LayoutInflater.from(parent.getContext())
            .inflate(R.layout.restaurant_list,parent, false);
    return new RestaurantViewHolder(view);
}

class RestaurantViewHolder extends RecyclerView.ViewHolder{

    TextView restaurant_Name, restaurant_Category,restaurant_Location;
    ImageView restaurant_Image;

    public RestaurantViewHolder(@NonNull View itemView){
        super(itemView);
        restaurant_Name = itemView.findViewById(R.id.restaurant_Name);
        restaurant_Category = itemView.findViewById(R.id.restaurant_Category);
        restaurant_Location = itemView.findViewById(R.id.restaurant_Location);
        restaurant_Image = itemView.findViewById(R.id.restaurant_Image);

    }
}

}

ResRecyclerViewActivity

public class ResRecyclerViewActivity extends AppCompatActivity {

private static final String TAG = "ResRecyclerViewActivity";
private RecyclerView restaurantRecyclerView;
private RestaurantAdapter adapter;

protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_restaurantlist);
    Log.d(TAG, "onCreate: started.");

    restaurantRecyclerView = findViewById(R.id.restaurant_rv);
    restaurantRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    FirebaseRecyclerOptions<RestaurantDetails> options =
            new FirebaseRecyclerOptions.Builder<RestaurantDetails>()
                    .setQuery(FirebaseDatabase.getInstance().getReference().child("Restaurant").child("Info"), RestaurantDetails.class)
                    .build();

    adapter = new RestaurantAdapter(options);
    restaurantRecyclerView.setAdapter(adapter);

}

@Override
protected void onStart() {
    super.onStart();
    adapter.startListening();
}

@Override
protected void onStop() {
    super.onStop();
    adapter.stopListening();
}

}

餐厅详情(模型)

public class RestaurantDetails {
private String name;
private String location;
private String address;
private String category;
private String image;
private Double latitude;
private Double longitude;


public RestaurantDetails(String name, String location, String address, String category, String image, Double latitude, Double longitude) {
    this.name = name;
    this.location = location;
    this.address = address;
    this.category = category;
    this.image = image;
    this.latitude = latitude;
    this.longitude = longitude;

}

public RestaurantDetails() {
}



public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getImage() {
    return image;
}

public void setImage(String image) { this.image = image; }

public String getLocation() {
    return location;
}

public void setLocation(String location) {
    this.location = location;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public String getCategory() {
    return category;
}

public void setCategory(String category) {
    this.category = category;
}

public Double getLatitude() {return latitude;}

public void setLatitude(Double lang) {this.latitude = latitude;}

public Double getLongitude() {return longitude;}

public void setLongitude(Double longitude) {this.longitude = longitude;}

}

当我调试应用程序时,这是弹出的 cmets。没有显示错误

【问题讨论】:

    标签: android firebase-realtime-database android-recyclerview


    【解决方案1】:

    这可能是由于 firebase 规则。检查您的 firebase 数据库规则,因为一个月后,出于安全原因,firebase 规则已更改为默认规则。

    【讨论】:

    • 我对规则进行了更改。但是,它似乎没有工作。还有其他部分吗,我需要调查一下,因为“编辑规则”似乎与影响布局有关,但我没有从中得到任何东西
    • 我刚刚更新了 JSON 文件。感谢您的评论
    猜你喜欢
    • 2021-07-03
    • 2013-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    相关资源
    最近更新 更多