简体   繁体   English

Android SimpleCursorTreeAdapter子级请点击

[英]Android SimpleCursorTreeAdapter Child Click

I have an expandable list using a simplecursortreeadapter 我有一个使用simplecursortreeadapter的可扩展列表

How would I integrate an onclicklistener or any way to change the 如何整合onclicklistener或以任何方式更改

Below is my script so far. 以下是到目前为止的脚本。 I was trying to use the onclicklistener at the bottom of this post, but I cannot figure out how to change it from a listview to expandable listview listener for the children. 我试图使用本文底部的onclicklistener,但无法弄清楚如何将其从子视图更改为子级的可扩展列表视图侦听器。

   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;
            }
    }

Tried implementing this 试图实现这一点

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);
            }   
        }       
);

EDIT: 编辑:

    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;
    }

At the moment the getChild(childPosition); 此刻getChild(childPosition); is outputting the error 正在输出错误

The method getItem(int) is undefined for the type Categories.MySimpleCursorTreeAdapter 对于类别类型,未定义方法getItem(int)。MySimpleCursorTreeAdapter

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM