Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在可扩展列表视图应用程序中从BaseExpandableListAdapter转换为SimpleCorsOrtreeAdapter_Android_Expandablelistview - Fatal编程技术网

Android 在可扩展列表视图应用程序中从BaseExpandableListAdapter转换为SimpleCorsOrtreeAdapter

Android 在可扩展列表视图应用程序中从BaseExpandableListAdapter转换为SimpleCorsOrtreeAdapter,android,expandablelistview,Android,Expandablelistview,可扩展列表视图应用程序,我试图将我的适配器从基本可扩展列表适配器(RuleBookAdapter.java)更改为简单可扩展列表适配器(RuleBookTreeAdapter.java),以访问我的内容提供商(TDAProvider) 我使用android SDK ApiDemos ExpandableList2.java作为模板来创建我的(RuleBookTreeAdapter.java)。我是Android开发的新手。我的目标是使用我的内容提供商实现适配器,这样我就可以生成更专业的应用程序。

可扩展列表视图应用程序,我试图将我的适配器从基本可扩展列表适配器(RuleBookAdapter.java)更改为简单可扩展列表适配器(RuleBookTreeAdapter.java),以访问我的内容提供商(TDAProvider)

我使用android SDK ApiDemos ExpandableList2.java作为模板来创建我的(RuleBookTreeAdapter.java)。我是Android开发的新手。我的目标是使用我的内容提供商实现适配器,这样我就可以生成更专业的应用程序。当我试图实现这一点时,我遇到了两个问题

第1期)在主活动(ActivityRuleBook.java)中,我将其更改为使用新适配器,如下所示:

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_expandable);
    elv=(ExpandableListView)findViewById(R.id.expandableListView1);
    elv.setAdapter(new RuleBookTreeAdapter());
//      elv.setAdapter(new RuleBookAdapter(this));
}
我得到错误“ExpandableListView类型中的方法setAdapter(ListAdapter)不适用于参数(RuleBookTreeAdapter)”。我不确定它在寻找哪个参数。我试图在android ApiDemos程序中找到调用程序,但没有结果,我搜索了internet和stackoverflow(建议和类似问题),除了SDK示例中的ExpandableList2.java之外,找不到一个由光标支持的SimpleCorSortreeAdapter的好例子

问题2)在SimpleCorsOrtreeAdapter(RuleBookTreeAdapter.getChildrenCursor)中,我不确定如何精确地调整查询以获取子数据

这是我数据库中2个表的布局,以及相关列

表:章节(这是应用程序中的父表) 列:_id,章节字符(2),章节标题字符(70) URI:CONTENT\u URI章节

表:规则(这是应用程序中的子表) 列:_id,rule varchar(10),chapter char(2),ruletitle char(50) URI:CONTENT\u URI\u规则

注意:规则表中的章节字段是章节表的外键。这些表中的数据是静态的,因此不会发生更新,并且每个父级至少有一个或多个子级

如有任何帮助或意见,我们将不胜感激,提前感谢您抽出时间。祝你今天愉快

主要活动源代码ActivityRuleBook.java

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ExpandableListView;
import android.widget.ListAdapter;

public class ActivityRuleBook extends Activity {

ExpandableListView elv;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_expandable);
    elv=(ExpandableListView)findViewById(R.id.expandableListView1);
    elv.setAdapter(new RuleBookTreeAdapter());
//      elv.setAdapter(new RuleBookAdapter(this));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.expandable, menu);
    return true;
}

}
RuleBookAdapter.java源代码。我原来的BaseExpandableListAdapter使用字符串,这很有效,我正在尝试替换它

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;


public class RuleBookAdapter extends BaseExpandableListAdapter {
private Context context;
String []grouplist={"01 Chapter","02 Chapter"};
String [][]childlist={
    {
        "01A Follow all rules","01B The USCF RULES"
    },
    {
        "02A The Rules are WRONG","02B The President is right"
    }
};
public RuleBookAdapter(Context context) {
    this.context=context;
}

@Override
public Object getChild(int arg0, int arg1) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    TextView tv=new TextView(context);
    tv.setText(childlist[groupPosition][childPosition]);
    tv.setPadding(60, 10, 10, 10);
    return tv;
}

@Override
public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub
    return childlist[groupPosition].length;
}

@Override
public Object getGroup(int groupPosition) {
    // TODO Auto-generated method stub
    return groupPosition;
}

@Override
public int getGroupCount() {
    // TODO Auto-generated method stub
    return grouplist.length;
}

@Override
public long getGroupId(int groupPosition) {
    // TODO Auto-generated method stub
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    TextView tv=new TextView(context);
    tv.setText(grouplist[groupPosition]);
    tv.setPadding(50, 10, 10, 10);
    tv.setTextColor(Color.RED);
    return tv;
}

@Override
public boolean hasStableIds() {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return true;
}

}
rulebooktreeeadapter.java源代码。我现在尝试实现的SimpleCursorTreeAdapter(从SDK ApiDemos ExpandableList2修改)getChildrenCursor中,我不确定如何精确地调整查询方式以从我的规则表中获取子数据。从ExpandableList2.java示例中我不清楚

import android.app.ExpandableListActivity;
import android.content.AsyncQueryHandler;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.widget.CursorTreeAdapter;
import android.widget.SimpleCursorTreeAdapter;

/**
* Demonstrates expandable lists backed by Cursors
*/
public class RuleBookTreeAdapter extends ExpandableListActivity {

private static final String[] CHAPTERS_PROJECTION = new String[] {
    TDAdb.KEY_ROWID,
    TDAdb.COL_CHAPTERTITLE
};
private static final int GROUP_ID_COLUMN_INDEX = 0;

private static final String[] RULES_PROJECTION = new String[] {
        TDAdb.KEY_ROWID,
        TDAdb.COL_RULETITLE
};

private static final int TOKEN_GROUP = 0;
private static final int TOKEN_CHILD = 1;

private static final class QueryHandler extends AsyncQueryHandler {
    private CursorTreeAdapter mAdapter;

    public QueryHandler(Context context, CursorTreeAdapter adapter) {
        super(context.getContentResolver());
        this.mAdapter = adapter;
    }

    @Override
    protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
        switch (token) {
        case TOKEN_GROUP:
            mAdapter.setGroupCursor(cursor);
            break;

        case TOKEN_CHILD:
            int groupPosition = (Integer) cookie;
            mAdapter.setChildrenCursor(groupPosition, cursor);
            break;
        }
    }
}

public class MyExpandableListAdapter extends SimpleCursorTreeAdapter {

    // Note that the constructor does not take a Cursor. This is done to avoid querying     the 
    // database on the main thread.
    public MyExpandableListAdapter(Context context, int groupLayout,
            int childLayout, String[] groupFrom, int[] groupTo, String[] childrenFrom,
            int[] childrenTo) {

        super(context, null, groupLayout, groupFrom, groupTo, childLayout,   childrenFrom,
                childrenTo);
    }

    @Override
    protected Cursor getChildrenCursor(Cursor groupCursor) {
        // Given the group, we return a cursor for all the children within that group 

        // Return a cursor that points to this chapters rules
        Uri.Builder builder = TDAProvider.CONTENT_URI_RULES.buildUpon();
        ContentUris.appendId(builder, groupCursor.getLong(GROUP_ID_COLUMN_INDEX));
//            builder.appendEncodedPath(TDAProvider.CONTENT_DIRECTORY);
        Uri rulesUri = builder.build();

        mQueryHandler.startQuery(TOKEN_CHILD, groupCursor.getPosition(), rulesUri, 
                RULES_PROJECTION, TDAdb.COL_CHAPTER + "=?", 
                null, null);
//            new String[] { TDAProvider.CONTENT_ITEM_TYPE }, null);

        return null;
    }
}

private QueryHandler mQueryHandler;
private CursorTreeAdapter mAdapter;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set up our adapter
    mAdapter = new MyExpandableListAdapter(
            this,
            android.R.layout.simple_expandable_list_item_1,
            android.R.layout.simple_expandable_list_item_1,
            new String[] { TDAdb.COL_CHAPTERTITLE }, // Name for group layouts
            new int[] { android.R.id.text1 },
            new String[] { TDAdb.COL_RULETITLE }, // Number for child layouts
            new int[] { android.R.id.text1 });

    setListAdapter(mAdapter);

    mQueryHandler = new QueryHandler(this, mAdapter);

    // Query for chapters
    mQueryHandler.startQuery(TOKEN_GROUP, null, TDAProvider.CONTENT_URI,      CHAPTERS_PROJECTION, 
            null, null, null);
}

@Override
protected void onDestroy() {
    super.onDestroy();

    // Null out the group cursor. This will cause the group cursor and all of the child    cursors
    // to be closed.
    mAdapter.changeCursor(null);
    mAdapter = null;
}
}
为了清晰和完整,我将包括我的数据库、数据库助手、内容提供者和布局xml文件。我已经在我的项目的其他变体中使用了这个源代码,并且似乎工作得很好

TDAdb.java源代码

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;


public class TDAdb {

     public static final String KEY_ROWID = "_id";
     public static final String COL_CHAPTER = "chapter";
     public static final String COL_CHAPTERTITLE = "chaptertitle";
    // public static final String KEY_CONTINENT = "continent";

      // Rule Table Columns
      public static final String COL_RULE = "rule";
//    public static final String COL_CHAPTER = "chapter";
      public static final String COL_KEYDESCRIPTOR = "keydescriptor";
      public static final String COL_RULETITLE = "ruletitle";
      public static final String COL_DESCR = "descr";
      public static final String COL_DESCRIPTION = "description";    //LongText
      public static final String COL_LABEL = "label";
      public static final String COL_USERLABEL = "userlabel";
      public static final String COL_LABELID = "labelid";           //Integer
      public static final String COL_USERLABELID = "userlabelid";   //Integer
      public static final String COL_TDTIP = "tdtip";
      public static final String COL_DEFUNCT = "defunct";
      public static final String COL_USCFREVISION = "uscfrevision";
      public static final String COL_HIGHLIGHT = "highlight";       //LongText
      public static final String COL_PAGENO = "pageno";
      public static final String COL_CHANGEDATE = "changedate";     //Integer
      public static final String COL_REFINC = "refinc";
      public static final String COL_RULEINC = "ruleinc";

     private static final String LOG_TAG = "CountriesDb";
     public static final String CHAPTER_TABLE = "chapters";
     public static final String RULE_TABLE = "rules";
     public static String SQLITE_TABLE = "chapters";

/*   private static final String DATABASE_CREATE =
      "CREATE TABLE if not exists " + CHAPTER_TABLE + " (" +
       KEY_ROWID + " integer PRIMARY KEY autoincrement," +
       COL_CHAPTER + "," +
       COL_CHAPTERTITLE + "," +
    //   KEY_CONTINENT + "," +
       " UNIQUE (" + COL_CHAPTER +"));"; */

     public static void onCreate(SQLiteDatabase db) {
//    Log.w(LOG_TAG, DATABASE_CREATE); 
//    db.execSQL(DATABASE_CREATE);
          Log.i(LOG_TAG, "onCreate");
     }

     public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      Log.w(LOG_TAG, "Upgrading database from version " + oldVersion + " to "
        + newVersion + ", which will destroy all old data");
//    db.execSQL("DROP TABLE IF EXISTS " + CHAPTER_TABLE);
      onCreate(db);
     }
}
TDAdbHelper.java源代码(包括完整性)

TDAProvider.java源代码(包括完整性)

Myactivity\u expadable.xml文件(为完整起见包括在内)

我从logcat获得以下错误:

06-07 17:12:31.139: E/AndroidRuntime(2226): FATAL EXCEPTION: main
06-07 17:12:31.139: E/AndroidRuntime(2226): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.birdsall.peter.expandable1/com.birdsall.peter.expandable1.ActivityRuleBook}: java.lang.ClassCastException: com.birdsall.peter.expandable1.RuleBookTreeAdapter cannot be cast to android.widget.ListAdapter
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.os.Looper.loop(Looper.java:137)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.main(ActivityThread.java:4424)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at java.lang.reflect.Method.invokeNative(Native Method)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at java.lang.reflect.Method.invoke(Method.java:511)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at dalvik.system.NativeStart.main(Native Method)
06-07 17:12:31.139: E/AndroidRuntime(2226): Caused by: java.lang.ClassCastException: com.birdsall.peter.expandable1.RuleBookTreeAdapter cannot be cast to android.widget.ListAdapter
06-07 17:12:31.139: E/AndroidRuntime(2226):     at com.birdsall.peter.expandable1.ActivityRuleBook.onCreate(ActivityRuleBook.java:19)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.Activity.performCreate(Activity.java:4465)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-07
17:12:31.139:E/AndroidRuntime(2226):。。。还有11个


在RuleBookTreeAdapter中实现该方法会导致大多数代码出错,因为它是一种不同类型的适配器。

Ken对列表适配器的看法是正确的,这是我为该活动调整的代码,需要进行大量研究。`package com.birdsall.tda

import android.app.ExpandableListActivity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.SimpleCursorTreeAdapter;
import android.widget.SimpleCursorTreeAdapter.ViewBinder;
import android.widget.TableRow;
import android.widget.TextView;

public class ActivityChapters extends ExpandableListActivity {

    private Context context;


    private Cursor mChapterCursor = null;
    private ExpandableListAdapter mExpandableListAdapter;
    private static final String TAG = "ActivityChapters";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 65, getResources().getDisplayMetrics());
        ContentResolver cr = this.getContentResolver();
        mChapterCursor = cr.query(TDAProvider.CONTENT_URI,
                TDAdb.PROJECTION_CHAPTER, null, null, TDAdb.COL_CHAPTER);

        setTitle("USCF Rule Book");
        Log.i(this.getClass().toString(), "... setTitle ");

        startManagingCursor(mChapterCursor);

        mExpandableListAdapter = new ChapterExpandableListAdapter(this,
                mChapterCursor, android.R.layout.simple_expandable_list_item_1,
                android.R.layout.simple_expandable_list_item_1,
                new String[] { TDAdb.COL_CHAPTERTITLE },
                new int[] { android.R.id.text1 },
                android.R.layout.simple_expandable_list_item_2,
                new String[] { TDAdb.COL_RULETITLE },
                new int[] { android.R.id.text1 });

        Log.i(this.getClass().toString(), "... after mExpandableListAdapter");
        setListAdapter(mExpandableListAdapter);

        int groupCount = mExpandableListAdapter.getGroupCount();
        ExpandableListView listView = getExpandableListView();


        ((SimpleCursorTreeAdapter) mExpandableListAdapter)
                .setViewBinder(new ViewBinder() {

                    public boolean setViewValue(View view, Cursor cursor,
                            int columnIndex) {
                        // parent
                        if (columnIndex == cursor
                                .getColumnIndex(TDAdb.COL_CHAPTERTITLE)) {
                            TextView v = (TextView) view;
                            v.setText((cursor.getString(cursor
                                    .getColumnIndex(TDAdb.COL_CHAPTER)))
                                    + " - "
                                    + (cursor.getString(cursor
                                            .getColumnIndex(TDAdb.COL_CHAPTERTITLE)))
                                    + " "       
                                    + (cursor.getString(cursor
                                            .getColumnIndex(TDAdb.COL_KEYDESC)))
                                    );
//                          v.setPadding(60, 10, 10, 10);
                            v.setTextColor(getResources().getColor(R.color.solid_red));
                            v.setTextSize(16);
//                          v.setMaxHeight(50);
//                          v.setHeight(50);
                            v.setMinimumHeight(50);
                            return true;
                        } else {
                            // child
                            if (columnIndex == cursor
                                    .getColumnIndex(TDAdb.COL_RULETITLE)) {
                                TextView v = (TextView) view;
                                String currentKeyDescriptor = (cursor.getString(cursor.getColumnIndex(TDAdb.COL_KEYDESCRIPTOR)));
                                String textKeyDescriptor = "";
                                if ((String)currentKeyDescriptor == "1") {
                                    textKeyDescriptor = "Club";
                                } else if ((String)currentKeyDescriptor == "2") {
                                    textKeyDescriptor = "USCF";
                                } else if ((String)currentKeyDescriptor == "3") {
                                    textKeyDescriptor = "TD Tip";
                                } else {
                                    textKeyDescriptor = "???";
                                }

                                Log.i(this.getClass().toString(), "... KeyDescriptor " + currentKeyDescriptor); 
                                v.setText("   "
                                        + (cursor.getString(cursor
                                                .getColumnIndex(TDAdb.COL_RULE)))
                                        + " - "
                                        + (cursor.getString(cursor
                                                .getColumnIndex(TDAdb.COL_RULETITLE)))
                                        + " (" 
                                        + (cursor.getString(cursor
                                                .getColumnIndex(TDAdb.COL_KEYDESCRIPTOR)))  
                                        + ")" + textKeyDescriptor       
                                        );
                                v.setTextColor(getResources().getColor(R.color.solid_blue));


                                return true;
                            }
                        }
                        return false;
                    }
                });

        Log.i(this.getClass().toString(), "... after ExpandableListView");
        setListAdapter(mExpandableListAdapter);
        Log.i(this.getClass().toString(), "... after setListAdapter");


    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
        // Intent intent = new Intent(this, ExecuteCheckListActivity.class);
        // intent.putExtra("checklist_id", id);
        // startActivity(intent);

        return true;
    }

    public class ChapterExpandableListAdapter extends SimpleCursorTreeAdapter {
        private Cursor dataAdapter;

        public ChapterExpandableListAdapter(Context context, Cursor cursor,
                int collapsedGroupLayout, int expandedGroupLayout,
                String[] groupFrom, int[] groupTo, int childLayout,
                String[] childFrom, int[] childTo) {

            super(context, cursor, collapsedGroupLayout, expandedGroupLayout,
                    groupFrom, groupTo, childLayout, childFrom, childTo);
            Log.i(this.getClass().toString(),
                    "... after super ChapterExpandableListAdapter");
        }

        @Override
        protected Cursor getChildrenCursor(Cursor groupCursor) {

            Log.i(this.getClass().toString(),
                    "... in getChildernCursor before RULES query");
            String[] selectionArgs = new String[] { (String) (groupCursor
                    .getString(groupCursor.getColumnIndex(TDAdb.COL_CHAPTER))) };
            ContentResolver cr = getContentResolver();
            dataAdapter = cr.query(TDAProvider.CONTENT_URI_RULES_DESCRIBED, TDAdb.PROJECTION_RULESDESCRIBED, TDAdb.COL_CHAPTER + " = ? ", selectionArgs, TDAdb.COL_RULE);
            Log.i(this.getClass().toString(),
                    "... in getChildernCursor after RULES query");
            startManagingCursor(dataAdapter);
            Log.i(this.getClass().toString(),
                    "... in getChildernCursor after Managing Cursor");

            return dataAdapter;
        }

    }

    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        TextView tv = new TextView(context);
        // tv = (TextView) convertView.findViewById(android.R.id.text1);
        tv.setPadding(60, 10, 10, 10);

        return convertView;
    }

}
`

问题1:
elv
是否定义为
ExpandableListView
ListView
?看起来setAdapter需要一个ListAdapter。Ken如上所述,我已经尝试过了。elv被定义为可扩展ListViews将不得不查看ListAdapter,在深入研究SDK APIDemos后,Expandablelist2不仅仅是一个ListAdapter。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/background" >

    <ExpandableListView
        android:id="@+id/expandableListView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:padding="2dp">

    </ExpandableListView>

</RelativeLayout>
    elv.setAdapter((ListAdapter) new RuleBookTreeAdapter());
06-07 17:12:31.139: E/AndroidRuntime(2226): FATAL EXCEPTION: main
06-07 17:12:31.139: E/AndroidRuntime(2226): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.birdsall.peter.expandable1/com.birdsall.peter.expandable1.ActivityRuleBook}: java.lang.ClassCastException: com.birdsall.peter.expandable1.RuleBookTreeAdapter cannot be cast to android.widget.ListAdapter
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.os.Looper.loop(Looper.java:137)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.main(ActivityThread.java:4424)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at java.lang.reflect.Method.invokeNative(Native Method)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at java.lang.reflect.Method.invoke(Method.java:511)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at dalvik.system.NativeStart.main(Native Method)
06-07 17:12:31.139: E/AndroidRuntime(2226): Caused by: java.lang.ClassCastException: com.birdsall.peter.expandable1.RuleBookTreeAdapter cannot be cast to android.widget.ListAdapter
06-07 17:12:31.139: E/AndroidRuntime(2226):     at com.birdsall.peter.expandable1.ActivityRuleBook.onCreate(ActivityRuleBook.java:19)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.Activity.performCreate(Activity.java:4465)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
06-07 17:12:31.139: E/AndroidRuntime(2226):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
06-07
import android.app.ExpandableListActivity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.SimpleCursorTreeAdapter;
import android.widget.SimpleCursorTreeAdapter.ViewBinder;
import android.widget.TableRow;
import android.widget.TextView;

public class ActivityChapters extends ExpandableListActivity {

    private Context context;


    private Cursor mChapterCursor = null;
    private ExpandableListAdapter mExpandableListAdapter;
    private static final String TAG = "ActivityChapters";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 65, getResources().getDisplayMetrics());
        ContentResolver cr = this.getContentResolver();
        mChapterCursor = cr.query(TDAProvider.CONTENT_URI,
                TDAdb.PROJECTION_CHAPTER, null, null, TDAdb.COL_CHAPTER);

        setTitle("USCF Rule Book");
        Log.i(this.getClass().toString(), "... setTitle ");

        startManagingCursor(mChapterCursor);

        mExpandableListAdapter = new ChapterExpandableListAdapter(this,
                mChapterCursor, android.R.layout.simple_expandable_list_item_1,
                android.R.layout.simple_expandable_list_item_1,
                new String[] { TDAdb.COL_CHAPTERTITLE },
                new int[] { android.R.id.text1 },
                android.R.layout.simple_expandable_list_item_2,
                new String[] { TDAdb.COL_RULETITLE },
                new int[] { android.R.id.text1 });

        Log.i(this.getClass().toString(), "... after mExpandableListAdapter");
        setListAdapter(mExpandableListAdapter);

        int groupCount = mExpandableListAdapter.getGroupCount();
        ExpandableListView listView = getExpandableListView();


        ((SimpleCursorTreeAdapter) mExpandableListAdapter)
                .setViewBinder(new ViewBinder() {

                    public boolean setViewValue(View view, Cursor cursor,
                            int columnIndex) {
                        // parent
                        if (columnIndex == cursor
                                .getColumnIndex(TDAdb.COL_CHAPTERTITLE)) {
                            TextView v = (TextView) view;
                            v.setText((cursor.getString(cursor
                                    .getColumnIndex(TDAdb.COL_CHAPTER)))
                                    + " - "
                                    + (cursor.getString(cursor
                                            .getColumnIndex(TDAdb.COL_CHAPTERTITLE)))
                                    + " "       
                                    + (cursor.getString(cursor
                                            .getColumnIndex(TDAdb.COL_KEYDESC)))
                                    );
//                          v.setPadding(60, 10, 10, 10);
                            v.setTextColor(getResources().getColor(R.color.solid_red));
                            v.setTextSize(16);
//                          v.setMaxHeight(50);
//                          v.setHeight(50);
                            v.setMinimumHeight(50);
                            return true;
                        } else {
                            // child
                            if (columnIndex == cursor
                                    .getColumnIndex(TDAdb.COL_RULETITLE)) {
                                TextView v = (TextView) view;
                                String currentKeyDescriptor = (cursor.getString(cursor.getColumnIndex(TDAdb.COL_KEYDESCRIPTOR)));
                                String textKeyDescriptor = "";
                                if ((String)currentKeyDescriptor == "1") {
                                    textKeyDescriptor = "Club";
                                } else if ((String)currentKeyDescriptor == "2") {
                                    textKeyDescriptor = "USCF";
                                } else if ((String)currentKeyDescriptor == "3") {
                                    textKeyDescriptor = "TD Tip";
                                } else {
                                    textKeyDescriptor = "???";
                                }

                                Log.i(this.getClass().toString(), "... KeyDescriptor " + currentKeyDescriptor); 
                                v.setText("   "
                                        + (cursor.getString(cursor
                                                .getColumnIndex(TDAdb.COL_RULE)))
                                        + " - "
                                        + (cursor.getString(cursor
                                                .getColumnIndex(TDAdb.COL_RULETITLE)))
                                        + " (" 
                                        + (cursor.getString(cursor
                                                .getColumnIndex(TDAdb.COL_KEYDESCRIPTOR)))  
                                        + ")" + textKeyDescriptor       
                                        );
                                v.setTextColor(getResources().getColor(R.color.solid_blue));


                                return true;
                            }
                        }
                        return false;
                    }
                });

        Log.i(this.getClass().toString(), "... after ExpandableListView");
        setListAdapter(mExpandableListAdapter);
        Log.i(this.getClass().toString(), "... after setListAdapter");


    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
        // Intent intent = new Intent(this, ExecuteCheckListActivity.class);
        // intent.putExtra("checklist_id", id);
        // startActivity(intent);

        return true;
    }

    public class ChapterExpandableListAdapter extends SimpleCursorTreeAdapter {
        private Cursor dataAdapter;

        public ChapterExpandableListAdapter(Context context, Cursor cursor,
                int collapsedGroupLayout, int expandedGroupLayout,
                String[] groupFrom, int[] groupTo, int childLayout,
                String[] childFrom, int[] childTo) {

            super(context, cursor, collapsedGroupLayout, expandedGroupLayout,
                    groupFrom, groupTo, childLayout, childFrom, childTo);
            Log.i(this.getClass().toString(),
                    "... after super ChapterExpandableListAdapter");
        }

        @Override
        protected Cursor getChildrenCursor(Cursor groupCursor) {

            Log.i(this.getClass().toString(),
                    "... in getChildernCursor before RULES query");
            String[] selectionArgs = new String[] { (String) (groupCursor
                    .getString(groupCursor.getColumnIndex(TDAdb.COL_CHAPTER))) };
            ContentResolver cr = getContentResolver();
            dataAdapter = cr.query(TDAProvider.CONTENT_URI_RULES_DESCRIBED, TDAdb.PROJECTION_RULESDESCRIBED, TDAdb.COL_CHAPTER + " = ? ", selectionArgs, TDAdb.COL_RULE);
            Log.i(this.getClass().toString(),
                    "... in getChildernCursor after RULES query");
            startManagingCursor(dataAdapter);
            Log.i(this.getClass().toString(),
                    "... in getChildernCursor after Managing Cursor");

            return dataAdapter;
        }

    }

    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        TextView tv = new TextView(context);
        // tv = (TextView) convertView.findViewById(android.R.id.text1);
        tv.setPadding(60, 10, 10, 10);

        return convertView;
    }

}
`