4

I have a listview where I have 50 elements being displayed. I have decided to paginate the view so on each part of the view there are 10 elements and then a next button is clicked to get to the next 10 elements. How can i set 10 data ? I follow this article http://rakhi577.wordpress.com/2013/05/20/listview-pagination-ex-2/ Here is my code .Can you help me with my code or a link to a guide on how to implement this correctly?

public class MainActivity extends ListActivity {


Context context;
Button btnSearch ;
EditText txtSearch;

private ProgressDialog pDialog;

// URL to get contacts JSON

    public int TOTAL_LIST_ITEMS = 50;
    public int NUM_ITEMS_PAGE   = 10;
    private int noOfBtns;
    private Button[] btns;


// JSON Node names
private static final String TAG_CONTACTS = "contacts";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
private static final String TAG_ADDRESS = "address";
private static final String TAG_GENDER = "gender";
private static final String TAG_PHONE = "phone";
private static final String TAG_PHONE_MOBILE = "mobile";
private static final String TAG_PHONE_HOME = "home";
private static final String TAG_PHONE_OFFICE = "office";

// contacts JSONArray
JSONArray contacts = null;

// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btnSearch=(Button)findViewById(R.id.buttonSearch);
    txtSearch=(EditText)findViewById(R.id.Searchtext);




}

public String gotourl()
{


    final  EditText txtSearch=(EditText)findViewById(R.id.Searchtext);

     String ts=txtSearch.getText().toString();

     String url = "http://latest.bloomapi.com/api/search?limit=50&offset=0&key1=last_name&op1=eq&value1="+ts;

    return url ;
}

public void Searchfunction(View v)

{
    Btnfooter();
    //loadList(0);
    CheckBtnBackGroud(0);
    contactList = new ArrayList<HashMap<String, String>>();

    ListView lv = getListView();




    // Listview on item click listener
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {



            // getting values from selected ListItem
            String name = ((TextView) view.findViewById(R.id.name))
                    .getText().toString();
            String cost = ((TextView) view.findViewById(R.id.email))
                    .getText().toString();
            String description = ((TextView) view.findViewById(R.id.mobile))
                    .getText().toString();

            // Starting single contact activity
            Intent in = new Intent(getApplicationContext(),
                    SingleContactActivity.class);
            in.putExtra(TAG_NAME, name);
            in.putExtra(TAG_EMAIL, cost);
            in.putExtra(TAG_PHONE_MOBILE, description);
            startActivity(in);

        }
    });

    // Calling async task to get json
    new GetContacts().execute();    
}
private void Btnfooter()
{
    int val = TOTAL_LIST_ITEMS%NUM_ITEMS_PAGE;
    val = val==0?0:1;
    noOfBtns=TOTAL_LIST_ITEMS/NUM_ITEMS_PAGE+val;

    LinearLayout ll = (LinearLayout)findViewById(R.id.btnLay);

    btns    =new Button[noOfBtns];

    for(int i=0;i<noOfBtns;i++)
    {
        btns[i] =   new Button(this);
        btns[i].setBackgroundColor(getResources().getColor(android.R.color.transparent));
        btns[i].setText(""+(i+1));

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        ll.addView(btns[i], lp);

        final int j = i;
        btns[j].setOnClickListener(new OnClickListener() {

            public void onClick(View v) 
            {
                //loadList(j);
                CheckBtnBackGroud(j);
            }
        });
    }

}

 private void CheckBtnBackGroud(int index)
    {

        for(int i=0;i<noOfBtns;i++)
        {
            if(i==index)
            {
                btns[index].setBackgroundDrawable(getResources().getDrawable(R.drawable.box_green));
                btns[i].setTextColor(getResources().getColor(android.R.color.white));
            }
            else
            {
                btns[i].setBackgroundColor(getResources().getColor(android.R.color.transparent));
                btns[i].setTextColor(getResources().getColor(android.R.color.black));
            }
        }

    }




private class GetContacts extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Showing progress dialog
        pDialog = new ProgressDialog(MainActivity.this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();

    }

    @Override
    protected Void doInBackground(Void... arg0) {
        // Creating service handler class instance
        ServiceHandler sh = new ServiceHandler();

        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(gotourl(), ServiceHandler.GET);

        Log.d("Response: ", "> " + jsonStr);

        if (jsonStr != null) {
            try {
                JSONObject jsonObj = new JSONObject(jsonStr);

                // Getting JSON Array node
                contacts = jsonObj.getJSONArray("result");

                // looping through All Contacts
                for (int i = 0; i < contacts.length(); i++) {
                    Integer a = contacts.length();
                    Log.d("loop", a.toString());
                    JSONObject c = contacts.getJSONObject(i);

                    String id = c.getString("npi");
                    String name = c.getString("first_name");
                    String email = c.getString("last_name");
                    //String address = c.getString(TAG_ADDRESS);
                    String gender = c.getString("type");


                    // tmp hashmap for single contact
                    HashMap<String, String> contact = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    contact.put("npi", id);
                    contact.put("first_name", name);
                    contact.put("last_name", email);
                    //contact.put(TAG_PHONE_MOBILE, mobile);

                    contact.put("type", gender);
                    // adding contact to contact list
                    contactList.add(contact);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            Log.d("ServiceHandler", "Couldn't get any data from the url");


        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        // Dismiss the progress dialog
        if (pDialog.isShowing())
            pDialog.dismiss();
        /**
         * Updating parsed JSON data into ListView
         * */
        ListAdapter adapter = new SimpleAdapter(
                MainActivity.this, contactList,
                R.layout.list_item, new String[] { "first_name", "last_name",
                        "type" }, new int[] { R.id.name,
                        R.id.email, R.id.mobile });

        setListAdapter(adapter);
    }

}}

enter image description here


I change the code. When i click next button[like 2,3,4,5]. showing first page data. Here is my modified code.Any help Appreciated :

public class MainActivity extends ListActivity {

private TextView title;
Context context;
Button btnSearch ;
EditText txtSearch;
private ListView listview;

private ProgressDialog pDialog;

// URL to get contacts JSON

    public int TOTAL_LIST_ITEMS = 50;
    public int NUM_ITEMS_PAGE   = 10;
    private int noOfBtns;
    private Button[] btns;




// JSON Node names
private static final String TAG_CONTACTS = "contacts";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_EMAIL = "email";
private static final String TAG_ADDRESS = "address";
private static final String TAG_GENDER = "gender";
private static final String TAG_PHONE = "phone";
private static final String TAG_PHONE_MOBILE = "mobile";
private static final String TAG_PHONE_HOME = "home";
private static final String TAG_PHONE_OFFICE = "office";

// contacts JSONArray
JSONArray contacts = null;

// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btnSearch=(Button)findViewById(R.id.buttonSearch);
    txtSearch=(EditText)findViewById(R.id.Searchtext);
    title    = (TextView)findViewById(R.id.title);

}

public String gotourl()
{


     final  EditText txtSearch=(EditText)findViewById(R.id.Searchtext);

     String ts=txtSearch.getText().toString();

     String url = "http://latest.bloomapi.com/api/search?limit=50&offset=0&key1=last_name&op1=eq&value1="+ts;

     return url ;
}

public void Searchfunction(View v)

{
    Btnfooter();


    CheckBtnBackGroud(0);
    contactList = new ArrayList<HashMap<String, String>>();

    ListView lv = getListView();




    // Listview on item click listener
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            if(position%2==0)
            {
                view.setBackgroundColor(Color.parseColor("#F4FA58"));

            }else
            {
            view.setBackgroundColor(Color.parseColor("#DA81F5"));
            }

            // getting values from selected ListItem
            String name = ((TextView) view.findViewById(R.id.name))
                    .getText().toString();
            String cost = ((TextView) view.findViewById(R.id.email))
                    .getText().toString();
            String description = ((TextView) view.findViewById(R.id.mobile))
                    .getText().toString();

            // Starting single contact activity
            Intent in = new Intent(getApplicationContext(),
                    SingleContactActivity.class);
            in.putExtra(TAG_NAME, name);
            in.putExtra(TAG_EMAIL, cost);
            in.putExtra(TAG_PHONE_MOBILE, description);
            startActivity(in);

        }
    });

    // Calling async task to get json
    new GetContacts().execute();    
}
private void Btnfooter()
{
    int val = TOTAL_LIST_ITEMS%NUM_ITEMS_PAGE;
    val = val==0?0:1;
    noOfBtns=TOTAL_LIST_ITEMS/NUM_ITEMS_PAGE+val;

    LinearLayout ll = (LinearLayout)findViewById(R.id.btnLay);

    btns    =new Button[noOfBtns];

    for(int i=0;i<noOfBtns;i++)
    {
        btns[i] =   new Button(this);
        btns[i].setBackgroundColor(getResources().getColor(android.R.color.transparent));
        btns[i].setText(""+(i+1));

        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        ll.addView(btns[i], lp);

        final int j = i;
        btns[j].setOnClickListener(new OnClickListener() {

            public void onClick(View v) 
            {

                new GetContacts().execute();    
                CheckBtnBackGroud(j);
            }


        });
    }

}

 private void CheckBtnBackGroud(int index)
    {
      title.setText("Page "+(index+1)+" of "+noOfBtns);
        for(int i=0;i<noOfBtns;i++)
        {
            if(i==index)
            {
                btns[index].setBackgroundDrawable(getResources().getDrawable(R.drawable.box_green));
                btns[i].setTextColor(getResources().getColor(android.R.color.white));
            }
            else
            {
                btns[i].setBackgroundColor(getResources().getColor(android.R.color.transparent));
                btns[i].setTextColor(getResources().getColor(android.R.color.black));
            }
        }

    }




private class GetContacts extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Showing progress dialog
        pDialog = new ProgressDialog(MainActivity.this);
        pDialog.setMessage("Please wait...");
        pDialog.setCancelable(false);
        pDialog.show();

    }

    @Override
    protected Void doInBackground(Void... arg0) {
        // Creating service handler class instance
        ServiceHandler sh = new ServiceHandler();

        // Making a request to url and getting response
        String jsonStr = sh.makeServiceCall(gotourl(), ServiceHandler.GET);

        Log.d("Response: ", "> " + jsonStr);

        if (jsonStr != null) {
            try {
                JSONObject jsonObj = new JSONObject(jsonStr);

                int number = 0;
                int start = number * NUM_ITEMS_PAGE;


                // looping through All Contacts




                // Getting JSON Array node
                contacts = jsonObj.getJSONArray("result");

                // looping through All Contacts
                //for (int i = 0; i < contacts.length(); i++) {
                for(int i=start;i<(start)+NUM_ITEMS_PAGE;i++) {


                    Integer a = contacts.length();
                    Log.d("loop", a.toString());
                    JSONObject c = contacts.getJSONObject(i);

                    String id = c.getString("npi");
                    String name = c.getString("first_name");
                    String email = c.getString("last_name");

                    String gender = c.getString("type");


                    // tmp hashmap for single contact
                    HashMap<String, String> contact = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    contact.put("npi", id);
                    contact.put("first_name", name);
                    contact.put("last_name", email);
                    //contact.put(TAG_PHONE_MOBILE, mobile);

                    contact.put("type", gender);
                    // adding contact to contact list
                    contactList.add(contact);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else {
            Log.d("ServiceHandler", "Couldn't get any data from the url");


        }

        return null;
    }



    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        // Dismiss the progress dialog
        if (pDialog.isShowing())
            pDialog.dismiss();
        /**
         * Updating parsed JSON data into ListView
         * */
        ListAdapter adapter = new SimpleAdapter(
                MainActivity.this, contactList,
                R.layout.list_item, new String[] { "first_name", "last_name",
                        "type" }, new int[] { R.id.name,
                        R.id.email, R.id.mobile });

        setListAdapter(adapter);
    }

}}
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview – Skynet Feb 24 '14 at 06:56
  • @NunChai Thanks for response my questions. But this is not my requirement –  Feb 24 '14 at 06:59
  • http://www.androidhive.info/2012/03/android-listview-with-load-more-button/ – Skynet Feb 24 '14 at 07:13
  • @NunChai I already check this. Can you understand what i am saying there ? –  Feb 24 '14 at 07:15
  • 1
    You have REST API as you have mentioned, you just need to include some pagination parameters in the request to the REST API, like current page, total pages, number of records, etc. – Paresh Mayani Feb 24 '14 at 12:51
  • how to implement pagination with restapi my input object having pagenumber and results per page and the fetch the data set to adapter but in second request fetch data but how to update with existing adapter data please help me – Harsha May 20 '15 at 06:19

1 Answers1

1

Below is my code to show list view with pagination. There is two blue button for change pages.

You can customize according to you need.

Create UserCategory.java

    package com.UserCategory;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;

public class UserCategory extends Activity implements OnClickListener{
private final int PAGE_SIZE = 5;
private int StartingIndex = 0;
ArrayList<String> userClass=new ArrayList<String>();
int textlength=0;

private String lv_arr[];
private ListView lv1;
EditText searchText;

//Button Previous;

private String Machine[]={"Machine 1","Machine 2","Machine 3","Machine 4","Machine 5","Machine 6","Machine 7","Machine 8","Machine 9","Machine 10","Machine 11","Machine 12","Machine 1","Machine 2","Machine 3","Machine 4","Machine 5","Machine 6","Machine 7","Machine 8","Machine 9","Machine 10","Machine 11","Machine 12"};
ImageView next,Previous;

@Override        
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
      this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.main);
        lv1=(ListView)findViewById(R.id.ListView01);
        searchText=(EditText)findViewById(R.id.et_Serchlist);
        next=(ImageView)findViewById(R.id.btn_next);
        Previous=(ImageView)findViewById(R.id.btn_previous);
        next.setOnClickListener(this);
        Previous.setOnClickListener(this);       
     //parsing();
    lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , Machine));
    changeListViewModel(0);


   }
private void changelist(int startingIndex) {

    if(startingIndex < 0) {
        Previous=(ImageView)findViewById(R.id.btn_previous);
        ImageView back=(ImageView)findViewById(R.id.btn_Whiteprevious);
        back.setVisibility(1);
        Previous.setVisibility(4);
        startingIndex = 0;
    }else if(startingIndex >= userClass.size())
        startingIndex -= PAGE_SIZE;
    StartingIndex   = startingIndex;
    int endingIndex = startingIndex + PAGE_SIZE;

    System.out.println("ending index"+endingIndex);
    if(StartingIndex!=0){
        Previous=(ImageView)findViewById(R.id.btn_previous);
        ImageView back=(ImageView)findViewById(R.id.btn_Whiteprevious);
        back.setVisibility(4);
        Previous.setVisibility(1);


    }
    if(endingIndex == userClass.size()){
        ImageView Forward=(ImageView)findViewById(R.id.btn_grewforward);
        Forward.setVisibility(1);
         next=(ImageView)findViewById(R.id.btn_next);
         next.setVisibility(4);
    }
    if(endingIndex != userClass.size()){
        ImageView Forward=(ImageView)findViewById(R.id.btn_grewforward);
        Forward.setVisibility(4);
         next=(ImageView)findViewById(R.id.btn_next);
         next.setVisibility(1);
    }
    if(endingIndex > userClass.size()) endingIndex = userClass.size();
    try {

        String[] subSet = getDataSubset1(startingIndex, endingIndex);
        System.out.println("subSet array"+subSet);
        lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , subSet));

    } catch (Exception e) {
        e.printStackTrace();
    }
}
private String[] getDataSubset1(int startingIndex, int endingIndex){
    String[] changeList = new String[endingIndex - startingIndex];
    int index = -1;
    for(int x = startingIndex; x < endingIndex; x++)

        changeList[++index] = userClass.get(x);


    return changeList;

}

private void changeListViewModel(int startingIndex){

    if(startingIndex < 0) {
        Previous=(ImageView)findViewById(R.id.btn_previous);
        ImageView back=(ImageView)findViewById(R.id.btn_Whiteprevious);
        back.setVisibility(1);
        Previous.setVisibility(4);
        startingIndex = 0;
    }

    else if(startingIndex >= Machine.length){

        startingIndex -= PAGE_SIZE;
    }
        System.out.println("strating"+startingIndex);

    System.out.println("startingIndex"+startingIndex);
    StartingIndex   = startingIndex;
    int endingIndex = startingIndex + PAGE_SIZE;
    System.out.println("endingIndex"+endingIndex);
     if(StartingIndex!=0)
     {
        Previous=(ImageView)findViewById(R.id.btn_previous);
        ImageView back=(ImageView)findViewById(R.id.btn_Whiteprevious);
        back.setVisibility(4);
        Previous.setVisibility(1);
        }
     if(endingIndex == userClass.size()){
            ImageView Forward=(ImageView)findViewById(R.id.btn_grewforward);
            Forward.setVisibility(1);
             next=(ImageView)findViewById(R.id.btn_next);
             next.setVisibility(4);
        }
     if(endingIndex != userClass.size()){
            ImageView Forward=(ImageView)findViewById(R.id.btn_grewforward);
            Forward.setVisibility(4);
             next=(ImageView)findViewById(R.id.btn_next);
             next.setVisibility(1);
        }
    System.out.println("ending index"+endingIndex);
    if(endingIndex > Machine.length) {

        endingIndex = Machine.length;
        ImageView Forward=(ImageView)findViewById(R.id.btn_grewforward);
        Forward.setVisibility(1);
         next=(ImageView)findViewById(R.id.btn_next);
         next.setVisibility(4);
    }


    String[] subSet = getDataSubset(startingIndex, endingIndex);
    System.out.println("subSet main array"+subSet.length);
    lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , subSet));
}

private String[] getDataSubset(int startingIndex, int endingIndex){
    String[] toRet = new String[endingIndex - startingIndex];
    int index = -1;
    System.out.println("index"+index);
    for(int x = startingIndex; x < endingIndex; x++)
        toRet[++index] = Machine[x];

    return toRet;

}
private void parsing() {
    // TODO Auto-generated method stub
    try {

        URL url = new URL("http://10.10.1.100/DogEventsWebService/EventService.svc/categories/1");
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new InputSource(url.openStream()));
        doc.getDocumentElement().normalize();

        NodeList nodeList = doc.getElementsByTagName("UserCategory");
        Machine = new String[nodeList.getLength()];


        for (int i = 0; i < nodeList.getLength(); i++) 
        {

            Node node = nodeList.item(i);
            Machine[i] = new String();

            Element fstElmnt = (Element) node;
            NodeList nameList = fstElmnt.getElementsByTagName("ClassDescription");
            Element nameElement = (Element) nameList.item(0);
            nameList = nameElement.getChildNodes();
            Machine[i]=((Node) nameList.item(0)).getNodeValue();
         }

        System.out.println("after for loop Machine"+Machine);

    } catch (Exception e) {
        System.out.println("XML Pasing Excpetion = " + e);
    }
}
@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.btn_next:

        textlength=searchText.getText().length();
        System.out.println("nextbutton"+textlength);
        if(textlength==0){
            changeListViewModel(StartingIndex + PAGE_SIZE);
        }else{
            changelist(StartingIndex + PAGE_SIZE);
            }

        break;
    case R.id.btn_previous:
        textlength=searchText.getText().length();
        if(textlength==0){
        changeListViewModel(StartingIndex - PAGE_SIZE);
        }else{
        changelist(StartingIndex - PAGE_SIZE);
        }
         break;
        default:
        break;
     }
}

}

create main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <View android:layout_height="35dp" 
      android:layout_width="fill_parent" 
      android:background="#ffffff"/>
  <TextView  android:id="@+id/tv_header"
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/hello" 
       android:layout_alignParentTop="true" 
       android:layout_marginLeft="0dp"
       android:textSize="25dp"/>
       <EditText 
       android:id="@+id/et_Serchlist" 
     android:layout_height="35dp" 
     android:paddingLeft="19dp"
      android:layout_marginLeft="60dp"
     android:layout_toRightOf="@+id/tv_header"
     android:maxLength="20"
     android:maxLines="1"
     android:inputType="text"
     android:hint="Search" 
     android:textColor="#ffffff"
     android:background="@drawable/my_border"
     android:layout_width="100dip"/>
  <ListView 
   android:id="@+id/ListView01"
   android:layout_width="fill_parent"
   android:textSize="4px" 
   android:layout_below="@+id/tv_header"
   android:layout_above="@+id/btn_previous"
   android:layout_height="wrap_content" />
     <View android:layout_height="55dp" 
       android:layout_below="@+id/ListView0"
       android:layout_alignParentBottom="true"
       android:layout_width="fill_parent" 
       android:background="#ffffff"/>
        <ImageView 
        android:src="@drawable/grewprevious"  
        android:id="@+id/btn_Whiteprevious" 
        android:layout_width="wrap_content" 
       android:layout_marginLeft="12dp"
    android:layout_marginBottom="6dp"
    android:layout_below="@+id/ListView0" 
   android:visibility="invisible"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content"/>
      <ImageView 
        android:src="@drawable/right"  
        android:id="@+id/btn_grewforward" 
        android:layout_width="wrap_content" 
        android:layout_marginLeft="259dp"
        android:layout_marginBottom="6dp"
        android:layout_below="@+id/ListView0" 
        android:visibility="invisible"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content"/>
     <ImageView 
        android:src="@drawable/backward" 
       android:id="@+id/btn_previous"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:layout_marginLeft="12dp"
       android:layout_marginBottom="6dp"
       android:layout_below="@+id/ListView0"
       android:onClick="backButtonClicked"/>

    <ImageView android:src="@drawable/forward" 
     android:id="@+id/btn_next"
    android:layout_width="80dp" 
    android:layout_marginBottom="6dp"
    android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" 
   android:layout_below="@+id/ListView0"
   android:layout_marginLeft="249dp"
    android:text="Next" 
    android:onClick="nextButtonClicked"/>   
</RelativeLayout>

Create userlist.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="match_parent">
  <TextView android:id="@+id/tv_className"
   android:layout_height="wrap_content" 
   android:layout_width="wrap_content"/> 
</LinearLayout>

Add my_border.xml into Drawable folder:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="2dip" android:color="#ee777777" />
<solid android:color="#ee444444"/>
<padding  
   android:left="20dip" 
  android:top="2dip" 
  android:right="20dip" 
  android:bottom="2dip" />
<corners android:radius="15dip" />
![enter image description here][1]</shape>

If it give error for iamges then use any other images and run application.

Let me know it work for you.

Thanks