I have an ExpandableListView and it has several headers and items in the Input fields. So I enter the data in the fields of the first header and click on the second header to populate its fields, but there they are already filled with the data that I entered in the first one, that is, I’m stupidly cloned.

What is the problem maybe help!?

Here is the BookingActivity itself :

public class BookingActivity extends BaseActivity { boolean isValid = true; ExpandableListAdapter listAdapter; ExpandableListView expListView; List<String> listDataHeader; HashMap<String, List<String>> listDataChild; int adultPassCount = GlobalAppData.FlightSearchValues.adultPassenger; int childPassCount = GlobalAppData.FlightSearchValues.childPassenger; int babyPassCount = GlobalAppData.FlightSearchValues.infPassenger; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.booking_layout); expListView = (ExpandableListView) findViewById(R.id.lvExp); prepareListData(); listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild); expListView.setAdapter(listAdapter); expListView.expandGroup(0); } public int GetPixelFromDips(float pixels) { final float scale = getResources().getDisplayMetrics().density; return (int) (pixels * scale + 0.5f); } private void prepareListData() { listDataHeader = new ArrayList<>(); listDataChild = new HashMap<>(); List<String> adult = null; List<String> child = null; List<String> baby = null; for (int i = 1; i <= adultPassCount; i++){ listDataHeader.add(getString(R.string.adultPassengers) + " " + i); adult = new ArrayList<>(); adult.add("Adult " + i); } for (int i = 1; i <= childPassCount; i++){ listDataHeader.add(getString(R.string.childPassengers) + " " + i); child = new ArrayList<>(); child.add("Child " + i); } for (int i = 1; i <= babyPassCount; i++){ listDataHeader.add(getString(R.string.infPassengers) + " " + i); baby = new ArrayList<>(); baby.add("Baby " + i); } for (int i = 0; i < adultPassCount; i++){ listDataChild.put(listDataHeader.get(i), adult); } if(childPassCount != 0){ for (int i = adultPassCount; i < adultPassCount + childPassCount; i++){ listDataChild.put(listDataHeader.get(i), child); } } if(babyPassCount != 0){ if(childPassCount != 0){ for (int i = adultPassCount + childPassCount; i < adultPassCount + childPassCount + babyPassCount; i++){ listDataChild.put(listDataHeader.get(i), baby); } } for (int i = adultPassCount; i < adultPassCount + babyPassCount; i++){ listDataChild.put(listDataHeader.get(i), baby); } } } 

ExpandableListAdapter:

 public class ExpandableListAdapter extends BaseExpandableListAdapter { String[] countries; private Context _context; private List<String> _listDataHeader; private HashMap<String, List<String>> _listDataChild; String[] data; public static EditText etBookingName; public static EditText etBookingLastname; public static EditText etBookingBirthday; public static AutoCompleteTextView etBookingNationality; public static Spinner spinner; public static EditText etBookingPassport; public static EditText etExpiryDate; public ExpandableListAdapter(Context context, List<String> listDataHeader, HashMap<String, List<String>> listChildData) { this._context = context; this._listDataHeader = listDataHeader; this._listDataChild = listChildData; } @Override public Object getChild(int groupPosition, int childPosititon) { return this._listDataChild.get(this._listDataHeader.get(groupPosition)) .get(childPosititon); } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater infalInflater = (LayoutInflater) this._context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.booking_list_items, null); etBookingNationality = (AutoCompleteTextView) convertView.findViewById(R.id.etBookingNationality); etBookingName = (EditText) convertView.findViewById(R.id.etBookingName); etBookingLastname = (EditText) convertView.findViewById(R.id.etBookingLastname); etBookingBirthday = (EditText) convertView.findViewById(R.id.etBookingBirthday); etBookingPassport = (EditText) convertView.findViewById(R.id.etBookingPassport); rgBookingGender = (RadioGroup) convertView.findViewById(R.id.rgBookingGender); etExpiryDate = (EditText) convertView.findViewById(R.id.etDocumentExpiryDate); } }); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } return convertView; } 
  • I haven't mastered a lot of code, but the problem is in any way how you set the data to the headers. Try to completely clear the input fields before setting the data and check what and where the data comes from for substitution. - Yuriy SPb
  • To be honest, I didn’t really understand (What does it mean to clear the fields, how to check the data for the substitution) - DevOma
  • I read some code and didn’t see any headers there. We ask the question: what doesn’t work for you? .. - YuriySPb
  • ListDataHeader - it goes as the leader of each item, and listDataChild as a child - DevOma
  • I still have little idea that you want to tell the soulless machine with your code) Try, perhaps, in getChildView before return convertView; All empty view values. Well the text is there and so on. But in general ... You are trying to do something very strange. Static view fields in an adapter are definitely wrong. - Yuriy SPb

0