Diganta Diganta - 6 months ago 17
Java Question

How can i get custom ListView data in a ArrayList in Android

I have a ListView. There are 5 rows in the Listview. In each row of I have 2 edittext fields. After I write something to each row and in edit text field how can I get all the data in the Listview as an ArrayList?

Answer

I do it for you. 1000% it will work. If you have list like this... enter image description here

    ArrayList<YourListModel> arrayList = new ArrayList<YourListModel>();
    int totalList = yourListView.getChildCount();
    for (int i = 0; i < totalList ; i++) {
    View view = yourListView.getChildAt(i);
    EditText et_name = (EditText) iew.findViewById(R.id.name_et_id);
    EditText et_address = (EditText) iew.findViewById(R.id.addr_et_id);
    EditText et_mobile = (EditText) iew.findViewById(R.id.mob_et_id);
    YourListModel yourModel = new YourListModel();
    yourModel.setName(et_name.getText().toString());
    yourModel.setAddress(et_address.getText().toString());
    yourModel.setMobile(et_mobile.getText().toString());
    arrayList.add(yourModel);
    }

After this loop you will get all data in listview as much it have.

Comments