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());
...
现在,这是我的问题...我如何获取条目值?
请提供一些代码和/或更好地解释你的问题(最好用代码),因为现在它几乎不可理解。 –
一些需要添加到主题中的代码 – sirios