2011-09-11 79 views
0

我有使用simplecursortreeadapter的Android SimpleCursorTreeAdapter儿童点击

我将如何整合的onclicklistener或任何方式改变

下面是到目前为止我的脚本可扩展列表。我试图在这篇文章的底部使用onclicklistener,但我无法弄清楚如何将它从listview改为可扩展的listview监听器。

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

试图实现此

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

编辑:

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);在输出错误

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

+0

我做类似的东西在这里HTTP: //stackoverflow.com/questions/10611927/simplecursortreeadapter-and-cursorloader – toobsco42

回答

0
+0

谢谢。这看起来是正确的。你能提供任何样品和例子吗? – Somk

+0

这不是太复杂,但这里是一个:http://code.google.com/p/myandroidwidgets/source/browse/trunk/CustomExpandableListView/src/com/beanie/example/list/SampleActivity.java – Erdal

+0

谢谢。我编辑了上述帖子。我现在得到一个错误 – Somk