SQLite
 sql >> Baza danych >  >> RDS >> SQLite

Wyświetlanie danych w RecyclerView

Twój może spróbować

  1. W Twojej działalności

    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. Twój adapter wygląda jak

     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. Twój recycler_item.xml

    <?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. jak umieścić bazę danych i odczytać bazę danych z folderu zasobów android, które są tworzone i eksportowane w sqllite?

  2. Jak działa SQLite Avg()

  3. Jak sformatować wyniki zapytań SQLite w trybie TCL

  4. Z wyjątkiem SQLite

  5. Dołącz bazę danych w SQLite