2014-02-17 71 views
0

我有一個鏈接列表名稱類別。 進入這個鏈接列表我有像這樣的值:id,名稱,描述,條目(鏈接列表)從鏈接列表中獲取鏈接到鏈接列表中

在方法中,我得到一個包的id。現在我的問題是,我如何連接/輸入/使用ID從條目中獲取數據?

(編號,名稱,描述和輸入數據將被從數據庫中加載)從數據庫

加載,並將其添加到鏈表:

CRUDDatabase dbHandler = new CRUDDatabase(this); 
     SQLiteDatabase db1 = dbHandler.getWritableDatabase(); 
     dbHandler.open(); 

     String[] categoryColumns = {dbHandler.ID, dbHandler.NAME, dbHandler.DESCRIPTION}; 
     String[] entryColumns = {dbHandler.ID, dbHandler.CATEG_ID, dbHandler.NAME, dbHandler.DESCRIPTION}; 

     Cursor cursorLoadCategory = db1.query(dbHandler.tableCategory, categoryColumns, null, null, null, null, null); 
     cursorLoadCategory.moveToFirst(); 
     while(!cursorLoadCategory.isAfterLast()){ 

      String whereClause = dbHandler.CATEG_ID + "= ?"; 
      String whereArgs = String.valueOf(cursorLoadCategory.getInt(0)); 
      Cursor cr2 = db1.query(dbHandler.tableEntry, entryColumns,whereClause,new String[]{whereArgs},null,null,null); 
      cr2.moveToFirst(); 
      Log.v("Get Entry Data by ID: ", "" + whereClause+" ::: " + whereArgs); 

      LinkedList<Entry> entries = new LinkedList<Entry>(); 

       while(!cr2.isAfterLast()){ 
        entries.add(new Entry(cr2.getInt(0), cr2.getInt(1), cr2.getString(2), cr2.getString(3))); 

        cr2.moveToNext();      
       } 

      System.out.println("--- CREATE CATEGORY ---"); 
      Category category = new Category(cursorLoadCategory.getInt(0), cursorLoadCategory.getString(1), cursorLoadCategory.getString(2), null, null, null, entries);     


      MainActivity.categories.add(category); 

從在MainActivity:

@Override 
public void onClick(View v) { 

    ViewGroup elements = (ViewGroup)v.getParent(); 
    LinearLayout lL = (LinearLayout)elements.findViewById(R.id.CatTemp_menuBoxContainer); 
    int categoryId = (Integer)lL.getTag(); 


    Intent intentSelectedCategory = new Intent(MainActivity.this, ItemScreen.class); 
    intentSelectedCategory.putExtra("catId", (int)categoryId); 
    startActivity(intentSelectedCategory); 
    finish(); 

} 

From ItemScreen.java:

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

    setContentView(R.layout.item_screen); 

    Intent i = getIntent(); 
    Bundle extra = getIntent().getExtras(); 
    int categoryId = extra.getInt("catId"); 

    Log.v("THIS IS THE ID OF THIS CATEGORY:", ""+categoryId); 

    TextView headTBox = (TextView)findViewById(R.id.HeadTextBox); 
    headTBox.setText(MainActivity.categories.get(categoryId-1).getName()); 

...

現在,這是我的問題...我如何獲取條目值?

+4

請提供一些代碼和/或更好地解釋你的問題(最好用代碼),因爲現在它幾乎不可理解。 –

+0

一些需要添加到主題中的代碼 – sirios

回答

0

它看起來像你必須從鏈表的開始處開始,並通過每個節點比較束ID和類別節點ID。

祝你好運!