1. Are you ready for the Galaxy S20? Here is everything we know so far!

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

Discussion in 'Android Apps & Games' started by Achal Mehra, Apr 30, 2021.

  1. Achal Mehra

    Achal Mehra Lurker
    Thread Starter

    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) {
    e.printStackTrace();
    }

    myorderadapter adapter = new myorderadapter(MyordersActivity.this, arr_name, arr_mobile,
    arr_oid);


    listview.setAdapter(adapter);

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @override
    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();
    ru.execute();



    }

    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;

    }



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


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



    TextView orderid = row.findViewById(R.id.lv_item_oid);
    TextView custname = row.findViewById(R.id.lv_item_name);
    TextView custmobile = row.findViewById(R.id.lv_item_mobile);

    // now set our resources on views
    orderid.setText(roid[position]);
    custname.setText(rname[position]);
    custmobile.setText(rmobile[position]);


    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.
     



    1. Download the Forums for Android™ app!


      Download

       

ListView

ListView Forum

com.ilearn.listview

READ MORE
Last Updated
Rating
Installs
Loading...
Similar Threads - Listview custom Adaptor
  1. JamzApplications
    Replies:
    1
    Views:
    168
  2. frappydan
    Replies:
    6
    Views:
    564
  3. mlgch1
    Replies:
    0
    Views:
    1,108
  4. faran100
    Replies:
    0
    Views:
    499
  5. ElChief
    Replies:
    1
    Views:
    311
  6. Ponnangan
    Replies:
    0
    Views:
    522
  7. LefmyHans
    Replies:
    0
    Views:
    455
  8. Nightpoison
    Replies:
    1
    Views:
    468
  9. maneeshalampalli
    Replies:
    2
    Views:
    418
  10. maneeshalampalli
    Replies:
    4
    Views:
    1,297

Share This Page

Loading...