How to make poetry app in android studio
Introduction
In this article we will make ad-mob app number 15. In this app we will show poetry. So follow my all steps its very easy just copy and paste method. There are a lots of method to make poetry app like using images, text etc. I use text file and read file using input stream. You can earn money using this app. Please follow all steps.
Steps:
- Add Dependency in Build.Gradule
- Create layout, Name is itme_list.xml
- Create java class for Adapter, name is CustomAdapter.java
- Download Drawable file (Link )
- Paste assets file in asset folder and paste drawable file in drawable folder.
- Run your project . Enjoy!!
Build.Gradule
implementation 'com.android.support:recyclerview-v7:28.0.0'
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.v7.widget.RecyclerView android:background="@drawable/bac" android:id="@+id/recyclerview" android:layout_width="match_parent" android:layout_height="match_parent"> </android.support.v7.widget.RecyclerView> </LinearLayout>
item_list.xml
<?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"> <LinearLayout android:background="@android:color/black" android:layout_margin="12dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:background="@android:color/white" android:layout_margin="4dp" android:id="@+id/backgroudcolor" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:layout_width="40dp" android:layout_height="40dp" android:src="@drawable/quoete" android:layout_gravity="center" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="4dp" android:textColor="@android:color/white" android:id="@+id/poetry" android:text="Daway piyar ke mujhy nai aty !!!!!!! Aik zindagi h jb marzi mang lena" android:textSize="28dp" /> </LinearLayout> </LinearLayout> </LinearLayout>
CustomAdapter.java
import android.graphics.Color; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; import java.util.ArrayList; import java.util.List; public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.CustomHolder> { List <String> datarecv= new ArrayList<> ( ); public CustomAdapter(List<String> datarecv) { this.datarecv = datarecv; } @NonNull @Override public CustomHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { View view = LayoutInflater.from ( viewGroup.getContext () ).inflate ( R.layout.item_list,viewGroup,false ); return new CustomHolder ( view ); } @Override public void onBindViewHolder(@NonNull CustomHolder customHolder, int i) { String data= datarecv.get ( i ); customHolder.textView.setText ( data ); String []colors={"#0e59d1","#d10ea9","#8e0b8e","#5b8e0b","#8e5d0b"}; int color=i%colors.length; int intcolor= Color.parseColor ( colors[color] ); customHolder.linearLayout.setBackgroundColor ( intcolor ); } @Override public int getItemCount() { return datarecv.size (); } class CustomHolder extends RecyclerView.ViewHolder { TextView textView; LinearLayout linearLayout; public CustomHolder(@NonNull View itemView) { super ( itemView ); textView= (TextView)itemView.findViewById ( R.id.poetry ); linearLayout=(LinearLayout)itemView.findViewById ( R.id.backgroudcolor ); } } }
MainActivity.java
import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity { RecyclerView recyclerView; CustomAdapter customAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate ( savedInstanceState ); setContentView ( R.layout.activity_main ); recyclerView=(RecyclerView)findViewById ( R.id.recyclerview ); recyclerView.setLayoutManager ( new LinearLayoutManager ( this ) ); customAdapter=new CustomAdapter ( QuoteList () ); recyclerView.setAdapter ( customAdapter ); } private List<String> QuoteList() { List<String> quotes= new ArrayList<String> ( ); BufferedReader bufferedReader=null; ArrayList<String> items= new ArrayList<String>(); try { bufferedReader =new BufferedReader ( new InputStreamReader ( this.getAssets ().open ( "q.txt" ),"UTF-8" ) ); String lines=""; while ((lines=bufferedReader.readLine ())!=null) { quotes.add (lines ) ; } } catch (IOException a) { a.printStackTrace (); } finally { if(bufferedReader!=null) { try { bufferedReader.close (); } catch (IOException a) { a.printStackTrace (); } } } return quotes; } }
Download Data folder from step number step number 8. And paste files in drawable folder and assets folder.
Video will be uploaded in very soon.
Thanks