Thursday, October 19, 2017

Recycler view and card view in andeoid project

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="match_parent"    
android:layout_height="wrap_content"    
android:padding="10dp"    >

   

native add start testing








native add end testing

<android.support.v7.widget.CardView        
android:layout_width="match_parent"        
android:layout_height="75dp"        
android:id="@+id/cv"        >

        
<RelativeLayout            
android:layout_width="match_parent"            
android:layout_height="wrap_content"
            >

            
<ImageView                
android:layout_width="wrap_content"                
android:layout_height="75dp"                
android:id="@+id/bookphoto"                
android:src="@drawable/amirul"                
android:layout_alignParentLeft="true"                
android:layout_alignParentTop="true"                
android:layout_marginRight="16dp"               
 />

            
<TextView                
android:layout_width="wrap_content"                
android:layout_height="wrap_content"                
android:id="@+id/bookname"                
android:text="md amirul islam"                
android:layout_toRightOf="@+id/bookphoto"                
android:layout_alignParentTop="true"                
android:textSize="20sp"                
/>
<TextView                
android:layout_width="wrap_content"                
android:layout_height="wrap_content"                
android:id="@+id/booktitle"                
android:text="25 years old"                
android:layout_toRightOf="@+id/bookphoto"                
android:layout_below="@+id/bookname"              
  />

       
</RelativeLayout>

    
</android.support.v7.widget.CardView>

</LinearLayout>
 

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.edupointbd.amirul.ntcbebook.R;
import com.edupointbd.amirul.ntcbebook.adapter.MyAdapter;
import com.edupointbd.amirul.ntcbebook.model.Books;

import java.util.ArrayList;
import java.util.List;

public class AllBooks extends AppCompatActivity {

    RecyclerView recyclerView;
    MyAdapter myAdapter;
    List<Books>booksList;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_books);

        recyclerView = (RecyclerView)findViewById(R.id.rvbook);
        recyclerView.setHasFixedSize(true);
        LinearLayoutManager llm = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(llm);

        booksList = new ArrayList<>();

        myAdapter = new MyAdapter(new Books().getBooksList());
        recyclerView.setAdapter(myAdapter);




    }

}
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_all_books"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.edupointbd.amirul.ntcbebook.BookList.AllBooks">

    <android.support.v7.widget.RecyclerView        android:id="@+id/rvbook"        android:layout_width="match_parent"        android:layout_height="wrap_content">

    </android.support.v7.widget.RecyclerView>

</RelativeLayout>
package com.edupointbd.amirul.ntcbebook.model;

import com.edupointbd.amirul.ntcbebook.R;

import java.util.ArrayList;
import java.util.List;

/** * Created by Amirul on 18-Oct-17. */
public class Books {
    private String bookName;
   private String bookTitle;
   private int photoId;

    public Books(String bookName, String bookTitle, int photoId) {
        this.bookName = bookName;
        this.bookTitle = bookTitle;
        this.photoId = photoId;
    }

    private List<Books> booksList;

    public Books() {
        initializeData();
    }

    public void initializeData(){
        booksList = new ArrayList<>();
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));
        booksList.add(new Books("bangla","titile of bangla", R.drawable.amirul));

    }

    public String getBookTitle() {
        return bookTitle;
    }

    public String getBookName() {
        return bookName;
    }

    public int getPhotoId() {
        return photoId;
    }

    public List<Books> getBooksList() {
        return booksList;
    }
}