[英]Get value from a LinkedList into a LinkedList
我有一个链表名称类别。 进入此链表,我具有以下值:id,名称,描述,条目(链表)
在方法中,我得到了一个捆绑的ID。 现在我的问题是,如何使用ID连接/输入/获取条目中的数据?
(ID,名称,描述和条目数据将从数据库中加载)
从数据库加载并将其添加到LinkedList:
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();
}
从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());
...
现在这是我的问题...我如何获取条目值?
看来您必须从链表的开头开始,然后遍历每个节点,将包ID与类别节点ID进行比较。
祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.