SQLite
 sql >> Teknologi Basis Data >  >> RDS >> SQLite

Menampilkan data di RecyclerView

Anda dapat mencoba

  1. Dalam aktivitas Anda

    ArrayList<Author> authors = dbHandler. getAllAuthors();
    recyclerView.setHasFixedSize(true);
    
    // ListView
    recyclerView.setLayoutManager(new LinearLayoutManager(youractivity.this));
    
    
    // create an Object for Adapter
    CardViewDataAdapter1  mAdapter = new CardViewDataAdapter1(authors);
    
    // set the adapter object to the Recyclerview
    recyclerView.setAdapter(mAdapter);
    
  2. Adaptor Anda terlihat seperti

     class CardViewDataAdapter1 extends RecyclerView.Adapter<CardViewDataAdapter1.ViewHolder> {
       private ArrayList<Author> dataSet;
    
    
    public CardViewDataAdapter1(ArrayList<Author> os_versions) {
    
        dataSet = os_versions;
    }
    
    
    @Override
    public CardViewDataAdapter1.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
      // create a new view
        View itemLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(
                R.layout.recycler_item, null);
    
        itemLayoutView.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT));
    
        // create ViewHolder
    
        CardViewDataAdapter1.ViewHolder viewHolder = new CardViewDataAdapter1.ViewHolder(itemLayoutView);
    
        return viewHolder;
    }
    
    @Override
    public void onBindViewHolder(CardViewDataAdapter1.ViewHolder viewHolder, int i) {
    
        Author fp = dataSet.get(i);
    
        viewHolder.tv_name.setText(fp.getName());
    
    
    
    
        viewHolder.menu = fp;
    }
    
    @Override
    public int getItemCount() {
    
        return dataSet.size();
    }
    
    public void updateList(List<Author> temp) {
        dataSet = (ArrayList<Author>) temp;
        notifyDataSetChanged();
    }
    
    // inner class to hold a reference to each item of RecyclerView
    public  class ViewHolder extends RecyclerView.ViewHolder {
    
        public TextView tv_name;
    
    
        public Author menu;
        public ViewHolder(View itemLayoutView) {
            super(itemLayoutView);
    
            tv_name = (TextView) itemLayoutView  .findViewById(R.id.tv_name);
    
    
           }
    
       }
     }
    
  3. recycler_item.xml Anda

    <?xml version="1.0" encoding="utf-8"?>
       <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      card_view:cardCornerRadius="5dp"
     card_view:cardBackgroundColor="#FFFFFF"
        card_view:cardUseCompatPadding="true"
       >
    <LinearLayout
      android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical">
        <TextView
            android:id="@+id/tv_name"
            android:layout_width="match_parent"
             android:layout_height="wrap_content"
            android:text="Enamul"/>
    
     </LinearLayout>
    
    </android.support.v7.widget.CardView>
    



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Bagaimana cara memilih kolom tertentu dari database kamar yang diberikan parameter tertentu dalam kueri kamar?

  2. Tambahkan Kolom ke Tabel yang Ada di SQLite

  3. Apakah praktik yang baik menggunakan ContentProvider untuk menangani operasi basis data?

  4. Bagaimana cara melewatkan data dari suatu aktivitas ke kelas java

  5. Perilaku Android SQLite Journal berubah?