Search in sources :

Example 1 with HistoryAdapter

use of me.yluo.ruisiapp.adapter.HistoryAdapter in project Ruisi by freedom10086.

the class FrageHistory method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    initToolbar(true, "浏览历史");
    addToolbarMenu(R.drawable.ic_delete_24dp).setOnClickListener(view -> {
        Dialog alertDialog = new AlertDialog.Builder(getActivity()).setTitle("清空历史记录").setMessage("你确定要清空浏览历史吗??").setPositiveButton("是的(=・ω・=)", (dialogInterface, i) -> {
            MyDB db = new MyDB(getActivity());
            db.clearHistory();
            datas.clear();
            adapter.notifyDataSetChanged();
            Toast.makeText(getActivity(), "浏览历史已清空~~", Toast.LENGTH_SHORT).show();
        }).setNegativeButton("取消", null).setCancelable(true).create();
        alertDialog.show();
    });
    RecyclerView recyclerView = mRootView.findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);
    SwipeRefreshLayout refreshLayout = mRootView.findViewById(R.id.refresh_layout);
    refreshLayout.setEnabled(false);
    adapter = new HistoryAdapter(getActivity(), datas);
    adapter.setPlaceHolderText("暂无浏览历史");
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.addItemDecoration(new MyListDivider(getActivity(), MyListDivider.VERTICAL));
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(adapter);
    refresh();
    return mRootView;
}
Also used : Bundle(android.os.Bundle) AsyncTask(android.os.AsyncTask) LayoutInflater(android.view.LayoutInflater) MyListDivider(me.yluo.ruisiapp.widget.MyListDivider) Dialog(android.app.Dialog) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BaseAdapter(me.yluo.ruisiapp.adapter.BaseAdapter) ViewGroup(android.view.ViewGroup) R(me.yluo.ruisiapp.R) ArrayList(java.util.ArrayList) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) AlertDialog(android.support.v7.app.AlertDialog) ReadHistoryData(me.yluo.ruisiapp.model.ReadHistoryData) MyDB(me.yluo.ruisiapp.database.MyDB) Toast(android.widget.Toast) View(android.view.View) HistoryAdapter(me.yluo.ruisiapp.adapter.HistoryAdapter) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) MyListDivider(me.yluo.ruisiapp.widget.MyListDivider) Dialog(android.app.Dialog) AlertDialog(android.support.v7.app.AlertDialog) RecyclerView(android.support.v7.widget.RecyclerView) HistoryAdapter(me.yluo.ruisiapp.adapter.HistoryAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) MyDB(me.yluo.ruisiapp.database.MyDB)

Aggregations

Dialog (android.app.Dialog)1 AsyncTask (android.os.AsyncTask)1 Bundle (android.os.Bundle)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Toast (android.widget.Toast)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 R (me.yluo.ruisiapp.R)1 BaseAdapter (me.yluo.ruisiapp.adapter.BaseAdapter)1 HistoryAdapter (me.yluo.ruisiapp.adapter.HistoryAdapter)1 MyDB (me.yluo.ruisiapp.database.MyDB)1 ReadHistoryData (me.yluo.ruisiapp.model.ReadHistoryData)1 MyListDivider (me.yluo.ruisiapp.widget.MyListDivider)1