Next we are going to create approval screen and add details screen and some more things related to background processing of application with UI handling: (runUI Thread and asynctask).
Hello Developers, we are meeting after long 2 months . I am sorry for this gap as you were waiting to complete the project with me. I was busy on project development. You can checkout link: The Executed Idea .
We were on to menu screen and were creating admin-side app. Back to the screens of approval of buyer and seller. We are going to show a list of these requests . The user interface required for both is same [ A List ], only data is going to change. So I am going to use same activity i.e ApprovalActivity class.
On Approval Activity, we need to differentiate the click of admin is for Approval Seller or Approval Buyer Button click, so we will differentiate it by passing one extra data called differentiate key as user_type as String in intent data from the MenuActivity class to ApprovalActivity class.
Add below bold line to intent toapprovalscreen on Button click of seller and buyer in MenuActivity class
toapprovalscreen=new Intent(MenuActivity.this,ApprovalActivity.class); toapprovalscreen.putExtra("user_type","Sellers"); //For Seller startActivity(toapprovalscreen);
toapprovalscreen=new Intent(MenuActivity.this,ApprovalActivity.class); toapprovalscreen.putExtra("user_type","Buyers"); //For Buyer startActivity(toapprovalscreen);
Now In ApprovalActivity class, we will get user_type data from intent extras data.
Intent dataFromMenu; //declaring under the class. String user_type=""; dataFromMenu=getIntent(); if(dataFromMenu.getStringExtra("user_type")!=null){ user_type=dataFromMenu.getStringExtra("user_type"); }
Now, we will design ui for this Approval Screen.
To view the list of seller or buyer requests we are going to use ListView ui view of android and update the list with fetched data. So back to R.layout.content_approval.xml,
In layout ,we will have main layout as Linear Layout, in that we will have ListView View.
content_approval.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" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="**Your Package Name***.ApprovalActivity" tools:showIn="@layout/activity_approval" android:orientation="vertical"> <ListView android:id="@+id/listapprove" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
For buttons refresh and close, we need it on toolbar ,So we need to first add icons to drawable folder. You can get icons from material icon . Then go to res-> menu -> create menu_approval.xml.
menu_approval.xml :
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/refresh" android:icon="@drawable/ic_refresh_white_24dp" android:orderInCategory="1" android:title="Refresh" app:showAsAction="always" /> <item android:title="Close" android:id="@+id/close" android:orderInCategory="2" app:showAsAction="always" android:icon="@drawable/ic_close_white_24dp" /> </menu>
Now ,we require a 2 TextView and 2 Buttons to show our data and view each cell
Now to show data in listview ,we need to customize it according to data and ui we want. So, now we are going to create one new layout with 2 textview and 2 buttons. So ,create a new layout file content_approval_cell.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/tvcellname" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:padding="4dp" android:text="Person Name" /> <TextView android:id="@+id/tvcellverify" android:padding="4dp" android:layout_below="@+id/tvcellname" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Verification Number"/> <Button android:text="Accept" android:id="@+id/btnapprove" android:layout_width="100dp" android:layout_marginTop="10dp" android:layout_marginLeft="50dp" android:layout_height="wrap_content" android:layout_below="@+id/tvcellverify" android:background="@drawable/btn_approve" android:textColor="#ffffff" /> <Button android:layout_toRightOf="@+id/btnapprove" android:layout_alignBaseline="@+id/btnapprove" android:id="@+id/btnreject" android:layout_width="100dp" android:text="REJECT" android:layout_marginLeft="15dp" android:textColor="#ffffff" android:background="@drawable/btn_reject" android:layout_height="wrap_content" /> </RelativeLayout>
You can use shapes to make button look more attractive.We will create two coloured shapes red and green and apply to button background. Create btn_approve.xml and do changes:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#058b29"/> <corners android:radius="8dp"/> <size android:height="30dp" android:width="100dp"/> <stroke android:width="2dp" android:color="#52f0ff"/> </shape>
Similarly create btn_reject.xml and do following :
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#e63c59"/> <corners android:radius="8dp"/> <size android:height="30dp" android:width="100dp"/> <stroke android:width="2dp" android:color="#52f0ff"/> </shape>
Next, We are going to have our list of data in ArrayList<> ,data container layout as content_approve_cell layout and to fill it in listview View, we need to write Base Adapters to fill the data into container and Set the listview adapter with this BaseAdapter class we going to create next.
Creating packages keeps the classes organised. Create a new Package called Adapters and in that create class CustomeAdapterApproval.java ,extending it to BaseAdapters class and Implement their methods : getCount(),getItem(),getItemId(), and getView().
package ***Your Package Name ***.Adapters; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; /** * Created by Shrenik on 4/6/2018. */ public class CustomeAdapterApproval extends BaseAdapter { @Override public int getCount() { return 0; } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return 0; } @Override public View getView(int i, View view, ViewGroup viewGroup) { return null; } }
We will back to this class again, The data we are going to show of a Seller or Buyer, to hold each person data we need to create one object model , lets create ModelUser.java in the new package called Models, create new Package as Models and two new classes as named before.
ModelUser.java
package **Your Default Package Name****.Models; public class ModelUser { private String strName; private String strVerificationCode; private String strIsVerify; private String strUserType; }
Back to ApprovalActivity.java, Now we need to declare, initialize arraylist,listview and set adapter with the above CustomeAdapterApproval class.
Let’s do declaration,Add these to the class scope..
ArrayList<ModelUser> listApprovalUser=new ArrayList(); ListView listviewapproval; CustomeAdapterApproval approvalAdapter;
Let’s Add Initialize the ListView and CustomAdapterApproval and set Listview adapter.
listviewapproval=(ListView)findViewById(R.id.listapprove); approvalAdapter=new CustomeAdapterApproval(ApprovalActivity.this,listApprovalUser); listviewapproval.setAdapter(approvalAdapter);
Somebody essentially help to make seriously posts I would state. This is the very first time I frequented your web page and thus far? I amazed with the research you made to make this particular publish amazing. Excellent job!
Everything is very open with a very clear description of the issues.
It was truly informative. Your site is useful. Many
thanks for sharing!
Thanks A Lot. Keep Visiting and Request More For Me whatever You need.
cBi9Cz Wow, great blog post.Thanks Again. Really Great.