0

接続されたアダプターを使用して ExpandableListView に取り組んでいます。基本的に、すべてのグループを常に展開するか、少なくとも作成時に展開する必要があります。これを解決するために、アダプターで expandAll() メソッドを構築しようとしています。すべてのデータ更新呼び出しを既にそこに向けたので、アダプターにそれが必要です。

BaseExpandableListAdapter を拡張するアダプターの expandAll() メソッドを次に示します。

public void expandAll(){
    System.out.println(this.getGroupCount());
    if(this.getGroupCount() == 0){
        return;
    }
    System.out.println("ExpandAll " + list + " " + this.getGroupCount());
    list.expandGroup(0);
    System.out.println("Expanded");
    for(int i = 0; i < this.getGroupCount() - 1; i++){
        System.out.println(this.getGroup(i));
        list.expandGroup(i);
    }
}

list は ExpandableListView への参照です。expandGroup(0); で nullpointer を取得します。

これがSystem.outです...

06-17 13:32:10.124: I/System.out(7501): 4
06-17 13:32:10.124: I/System.out(7501): ExpandAll android.widget.ExpandableListView@424dcab8 4

そして、ここにエラーがあります

06-17 13:32:10.129: E/AndroidRuntime(7501): FATAL EXCEPTION: main
06-17 13:32:10.129: E/AndroidRuntime(7501): android.view.InflateException: Binary XML file line #6: Error inflating class    com.SverkerSbrg.Spendo.Transaction.TransactionList.TransactionListFrame
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.LayoutInflater.createView(LayoutInflater.java:613)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at com.SverkerSbrg.Spendo.Transaction.TransactionList.TransactionListFragment.onCreateView(TransactionListFragment.java:15)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.view.ViewPager.populate(ViewPager.java:1012)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.view.ViewPager.populate(ViewPager.java:881)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.support.v4.view.ViewPager$3.run(ViewPager.java:237)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.Choreographer.doCallbacks(Choreographer.java:555)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.Choreographer.doFrame(Choreographer.java:524)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.os.Handler.handleCallback(Handler.java:615)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.os.Looper.loop(Looper.java:137)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.app.ActivityThread.main(ActivityThread.java:4921)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at java.lang.reflect.Method.invokeNative(Native Method)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at java.lang.reflect.Method.invoke(Method.java:511)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at dalvik.system.NativeStart.main(Native Method)
06-17 13:32:10.129: E/AndroidRuntime(7501): Caused by: java.lang.reflect.InvocationTargetException
06-17 13:32:10.129: E/AndroidRuntime(7501):     at java.lang.reflect.Constructor.constructNative(Native Method)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.view.LayoutInflater.createView(LayoutInflater.java:587)
06-17 13:32:10.129: E/AndroidRuntime(7501):     ... 28 more
06-17 13:32:10.129: E/AndroidRuntime(7501): Caused by: java.lang.NullPointerException
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.widget.ExpandableListView.expandGroup(ExpandableListView.java:624)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at android.widget.ExpandableListView.expandGroup(ExpandableListView.java:610)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at com.SverkerSbrg.Spendo.Transaction.TransactionList.TransactionListAdapter.expandAll(TransactionListAdapter.java:93)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at com.SverkerSbrg.Spendo.Transaction.TransactionList.TransactionListAdapter.loadNextMonth(TransactionListAdapter.java:84)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at com.SverkerSbrg.Spendo.Transaction.TransactionList.TransactionListAdapter.<init>(TransactionListAdapter.java:45)
06-17 13:32:10.129: E/AndroidRuntime(7501):     at com.SverkerSbrg.Spendo.Transaction.TransactionList.TransactionListFrame.<init>(TransactionListFrame.java:48)
06-17 13:32:10.129: E/AndroidRuntime(7501):     ... 31 more

編集、要求された xml:s

ListView を含むレイアウト

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ExpandableListView
    android:id="@+id/TransactionList_elvList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/TransactionList_llCommandLine"
    android:layout_alignParentLeft="true"
    android:divider="@null"
    android:dividerHeight="0dp" >

</ExpandableListView>

<LinearLayout
    android:id="@+id/TransactionList_llCommandLine"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true" >

    <TextView
        android:id="@+id/TransactionList_tvAdd"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/TransactionList_CommandLine_Add" />

    <TextView
        android:id="@+id/TransactionList_tvCommandLineDiv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/TransactionList_tvFilter"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="@string/TransactionList_CommandLine_Filter" />
</LinearLayout>



</RelativeLayout>

グループビュー

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TransacitonGroupTile_llParent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<TextView
    android:id="@+id/TransacitonGroupTile_tvDiv1"
    android:layout_width="match_parent"
    android:layout_height="2dip"
    android:background="@color/blue_3" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/TransacitonGroupTile_tvName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/TransacitonGroupTile_tvDiv2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/TransacitonGroupTile_tvTotal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Total"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="bold" />

</LinearLayout>

<TextView
    android:id="@+id/TransacitonGroupTile_tvDiv3"
    android:layout_width="match_parent"
    android:layout_height="2dip"
    android:background="@color/blue_3" />

</LinearLayout>

そしてチャイルドビュー

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TransactionTile_llParent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
    android:id="@+id/TransactionTile_tvCategory"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="   "/>

<TextView
    android:id="@+id/TransactionTile_tvDiv1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

<TextView
    android:id="@+id/TransactionTile_tvLabel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Label"/>

<TextView
    android:id="@+id/TransactionTile_tvDiv2"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"/>

<TextView
    android:id="@+id/TransactionTile_tvAmount"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="XXX"/>

</LinearLayout>

また、GUI から処理したときにリストが正しく機能することを強調したいと思います。groupClick でグループが正しく展開/折りたたまれます。

4

1 に答える 1