Я ищу способ загрузки данных в представление списка Expandale, вывод, который я хочу похож на изображение, прилагаемое к изображению here Для того, чтобы это было сделано динамично, лучше ли быть читать из csv? Или создать БД? Кроме того, при нажатии на подменю я хочу, чтобы появился ScrollView.Загрузите данные в ExpandableListView
Вот код до сих пор: Компоновка деятельности:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ExpandableListView
android:id= "@+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
The itemlayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/grp_child"
android:paddingLeft="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
И подэлемента:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/row_name"
android:paddingLeft="50dp"
android:focusable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
В своей деятельности я жёстко некоторые значения до сих пор, используя некоторые tutorials Я наткнулся на:
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photographers);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(),
R.layout.group_row,
new String[] { "Group Item" },
new int[] { R.id.row_name },
createChildList(),
R.layout.child_row,
new String[] {"Sub Item"},
new int[] { R.id.grp_child}
);
setListAdapter(expListAdapter);
}catch(Exception e){
System.out.println("Errrr +++ " + e.getMessage());
}
}
/* Creating the Hashmap for the row */
@SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
for(int i = 0 ; i < 15 ; ++i) { // 15 groups........
HashMap m = new HashMap();
m.put("Group Item","Group Item " + i); // the key and it's value.
result.add(m);
}
return (List)result;
}
@SuppressWarnings("unchecked")
private List createChildList() {
ArrayList result = new ArrayList();
for(int i = 0 ; i < 15 ; ++i) { // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for(int n = 0 ; n < 3 ; n++) {
HashMap child = new HashMap();
child.put("Sub Item", "Sub Item " + n);
secList.add(child);
}
result.add(secList);
}
return result;
}
public void onContentChanged () {
System.out.println("onContentChanged");
super.onContentChanged();
}
/* This function is called on each child click */
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,int childPosition,long id) {
System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
return true;
}
/* This function is called on expansion of the group */
public void onGroupExpand (int groupPosition) {
try{
System.out.println("Group expanding Listener => groupPosition = " + groupPosition);
}catch(Exception e){
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
}
}
Мне интересно, если это хорошая идея хранить данные, которые я хочу показать в отдельных файлах csv (один хранит данные для элементов, один для подэлементов. один для дополнительной информации в ScrollView), чтобы иметь идентификаторы идентификатора и для прямого чтения из CSV с помощью OpenCSVReader?
Я был бы признателен за любые советы, Благодаря
Вы создали ExpandableListView? Где данные, которые вы хотите загрузить? Можете ли вы показать нам свой код? –
Просто добавили его выше, спасибо! – VyaraG