Listview with custom Adaptor not populating and app returns to previous screen

Achal Mehra

Apr 30, 2021
Hi all

am using a custom adapter for Listview to display the records fetched from database. However when listview activity loads after a couple of seconds it returns to the prior activity without loading listview.

Part of my main activity code is :

for (int i = 0; i < userArray.length(); i++) {

JSONObject jsonObject = userArray.getJSONObject(i);

oid = jsonObject.getInt("oid");

mobile = jsonObject.getString("mobile");

name = jsonObject.getString("name");

arr_oid = oid;
arr_mobile = mobile;
arr_name = name;


} else {

Toast.makeText(getApplicationContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
} catch (JSONException e) {

myorderadapter adapter = new myorderadapter(MyordersActivity.this, arr_name, arr_mobile,


listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),"this is click",Toast.LENGTH_SHORT).show();




//executing the async task
Myorderdetails ru = new Myorderdetails();


custom adapter code is :

public class myorderadapter extends ArrayAdapter<String> {

Activity context;
String rname[];
String rmobile[];
int roid[];
Context c;

public myorderadapter(Activity context, String[] arr_name, String[] arr_mobile, int[] arr_oid) {

super(context, custom_myorder_table, arr_name);
this.context = context;
this.rname = arr_name;
this.rmobile = arr_mobile;
this.roid = arr_oid;


public View getView(int position,View view, ViewGroup parent) {

View row = Inflater.inflate(custom_myorder_table, null, true);

TextView orderid = row.findViewById(;
TextView custname = row.findViewById(;
TextView custmobile = row.findViewById(;

// now set our resources on views

return row;

App runs correctly and the listview screen displays the progress bar however before it could show listview populated with data, it simply returns to the previous screen.