无法在我的recyclerview上看到cardview

时间:2016-09-12 10:45:45

标签: java android firebase firebase-realtime-database

我无法在Android Studio的Cardview上看到recyclerview, 日志中没有显示错误

代码:

public class TabHistory extends Fragment {
    private RecyclerView rvHistory;
    private LinearLayoutManager linearLayoutManager;
    Calendar c = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    String waktu;

    TextView txt_no_history;

    private static final String TAG = "TabHistory";

    // Getting reference to Firebase Database
    // Firebass
    private Firebase mREf;
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myref = database.getReference();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_tab_history, container, false);

    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // do your variables initialisations here except Views!!!
    }

    @Override
    public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mREf = new Firebase(Config.FIREBASE_URL);

        // Widget
        txt_no_history = (TextView) view.findViewById(R.id.txt_no_history);

        // Recycler View
        rvHistory = (RecyclerView) view.findViewById(R.id.rvHIstory);
        rvHistory.setHasFixedSize(true);
        linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rvHistory.setLayoutManager(linearLayoutManager);

        waktu = c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND) + " " + sdf.format(c.getTime());


        final FirebaseRecyclerAdapter<HistoryObject, HistoryHolder> adapter = new FirebaseRecyclerAdapter<HistoryObject, HistoryHolder>(
                HistoryObject.class,
                R.layout.activity_cardhistory,
                HistoryHolder.class,
                myref.child("readings").getRef()
        ) {
            @Override
            protected void populateViewHolder(HistoryHolder viewHolder, HistoryObject model, int position) {
                if (txt_no_history.getVisibility() == View.VISIBLE) {
                    txt_no_history.setVisibility(View.GONE);
                }
                Log.d(TAG, "Data loaded");
                viewHolder.txt_tanggaljam.setText(model.getHum());
                viewHolder.txt_peringatan.setText(model.getTemp());
                viewHolder.img_icon.setImageResource(R.mipmap.ic_ket_menangis);
            }
        };
        rvHistory.setAdapter(adapter);

    }

    public static class HistoryHolder extends RecyclerView.ViewHolder {
        TextView txt_tanggaljam, txt_peringatan;
        ImageView img_icon;

        public HistoryHolder(View v) {
            super(v);
            txt_tanggaljam = (TextView) v.findViewById(R.id.txt_tanggaljam);
            txt_peringatan = (TextView) v.findViewById(R.id.txt_peringatan);
            img_icon = (ImageView) v.findViewById(R.id.img_icon);
        }
    }
}

我从firebase获取json并且没有错误。但是cardview没有显示

JSON

{"-KRNFj1bTumJ7k0Hpeco":{"date":"1473580821","hum":"29.0","temp":"31.0"}

0 个答案:

没有答案