
Всем доброго времени суток, помогите пожалуйста с небольшой проблемой в ExpandableListView.
Как при нажатии на текучий елемент списка менять его название на другой текст (скажем "123" к примеру). Огромное спасибо заранее!)
Программный код:
```
public class MainActivity extends AppCompatActivity {
ExpandableListView listView;
AdapterHelper adapterHelper;
SimpleExpandableListAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.expandableContainer);
adapterHelper = new AdapterHelper(this);
adapter = adapterHelper.getAdapter();
listView.setAdapter(adapter);
listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
String nameChild = adapterHelper.getChildText(groupPosition, childPosition);
Toast.makeText(adapterHelper.getCntx(), nameChild, Toast.LENGTH_SHORT).show();
return true;
}
});
}
}
Код адаптера:
public class AdapterHelper {
final String ATTR_GROUP_NAME = "groupName";
final String ATTR_CHILD_NAME = "itemName";
Context cntx;
private SimpleExpandableListAdapter adapter;
private String[] arrayGroups = {"Еспрессо", "Американо", "Капучино", "Лате", "Чай"};
private String[] arrEspresso = {"Рістеро (9)", "Еспесо (9)", "Пунго (9)", "Допіо (15)", "Романо (10)"};
private String[] arrAmericano = {"Макіато (11)", "Американо (9)", "Дабл Американо (15)", "Флет Уайт (17)", "Раф Кава (20)", "Раф Кава (25)"};
AdapterHelper(Context ctx){
cntx = ctx;
}
SimpleExpandableListAdapter getAdapter(){
ArrayList<Map<String, String>> groupData;
ArrayList<Map<String, String>> childDataItems;
ArrayList<ArrayList<Map<String, String>>> allArrs;
Map<String, String> map;
groupData = new ArrayList<Map<String, String>>();
for(String group : arrayGroups){
map = new HashMap<String, String>();
map.put("groupName", group);
groupData.add(map);
}
String[] groupFrom = new String[] {"groupName"};
int[] groupTo = new int[]{android.R.id.text1};
allArrs = new ArrayList<ArrayList<Map <String, String>>>();
childDataItems = new ArrayList<Map<String, String>>();
for (String espr: arrEspresso){
map = new HashMap<String, String>();
map.put("itemName", espr);
childDataItems.add(map);
}
allArrs.add(childDataItems);
childDataItems = new ArrayList<Map<String, String>>();
for (String amrc: arrAmericano){
map = new HashMap<String, String>();
map.put("itemName", amrc);
childDataItems.add(map);
}
allArrs.add(childDataItems);
String[] childFrom = new String[] {"itemName"};
int[] childTo = new int[] {android.R.id.text1};
adapter =
new SimpleExpandableListAdapter(cntx, groupData, android.R.layout.simple_expandable_list_item_1,
groupFrom, groupTo, allArrs, android.R.layout.simple_list_item_1, childFrom, childTo);
return adapter;
}
public Context getCntx(){ return cntx; }
public String getGroupText(int groupPos){
return ((Map<String, String>) adapter.getGroup(groupPos)).get(ATTR_GROUP_NAME);
}
public String getChildText(int groupPos, int childPos){
return ((Map<String, String>) adapter.getChild(groupPos, childPos)).get(ATTR_CHILD_NAME);
}
}
```







