首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >安卓SimpleCursorTreeAdapter儿童点击

安卓SimpleCursorTreeAdapter儿童点击
EN

Stack Overflow用户
提问于 2011-09-11 19:20:20
回答 1查看 2K关注 0票数 0

我有一个使用Simplecursortree适配器的可扩展列表

如何集成onclicklistener或任何更改

下面是我的剧本。我试图在这篇文章的底部使用onclicklistener,但是我想不出如何将它从listview更改为可扩展的listview侦听器。

代码语言:javascript
复制
   protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.cattest);

            SQLiteDatabase checkDB = null;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

            Cursor groupCursor = checkDB.rawQuery("SELECT * FROM countries", null);
            MySimpleCursorTreeAdapter mscta = new MySimpleCursorTreeAdapter(
                                                    this,
                                                    groupCursor,
                                                    R.layout.employee_list_item,
                                                    new String[] {"country"},
                                                    new int[] {R.id.country},
                                                    R.layout.employee_list_item,
                                                    new String[] {"employee"},
                                                    new int[] {R.id.lastName});
            setListAdapter(mscta);
            checkDB.close();


    }

    class MySimpleCursorTreeAdapter extends SimpleCursorTreeAdapter{

            public MySimpleCursorTreeAdapter(Context context, Cursor cursor,
                            int groupLayout, String[] groupFrom, int[] groupTo,
                            int childLayout, String[] childFrom, int[] childTo) {
                    super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childFrom,
                                    childTo);
            }


            @Override
            protected Cursor getChildrenCursor(Cursor groupCursor) {
                    String countryID = Integer.toString(groupCursor.getInt(0));
                    SQLiteDatabase checkDB = null;
                    checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

                    Cursor value = checkDB.rawQuery("SELECT * FROM employee WHERE _id='"+ countryID +"'", null);

                    String test = "";
                    if(value.moveToFirst())
                            test =  value.getInt(0) + ": " + value.getString(1);
                    while(value.moveToNext()){
                            test += ";" + value.getInt(0) + ": " + value.getString(1);
                    }
                    return value;
            }
    }

尝试实现这一点

代码语言:javascript
复制
questionList = (ListView) findViewById (R.id.list);
sample(typedText);

questionList.setOnItemClickListener(
        new OnItemClickListener()
        {                   
            public void onItemClick(AdapterView<?> arg0, View view,
                    int position, long id) {
                Intent intent = new Intent(All.this, com.second.app.Second.class);
                Cursor cursor = (Cursor) adapter.getItem(position);
                intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
                //Cursor cursor = (Cursor) adapter.getItem(position);
                //intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
                startActivity(intent);
            }   
        }       
);

编辑:

代码语言:javascript
复制
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
            int childPosition, long id) {
        // use groupPosition and childPosition to locate the current item in the adapter

            Intent intent = new Intent(Categories.this, com.second.app.Second.class);
            Cursor cursor = (Cursor) mscta.getItem(childPosition);
            intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
            //Cursor cursor = (Cursor) adapter.getItem(position);
            //intent.putExtra("EMPLOYEE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
            startActivity(intent);

        return true;
    }

目前,getChild(childPosition);正在输出错误

Categories.MySimpleCursorTreeAdapter类型的getItem(int)方法未定义

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-09-11 19:37:48

查看setOnChildClickListener方法:http://developer.android.com/reference/android/widget/ExpandableListView.html#setOnChildClickListener(android.widget.ExpandableListView.OnChildClickListener

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7380639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档