JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java ME、Google Android 平台與 JavaCard 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
作者 各位大大!請問在Android裡的CursorTreeAdapter,如何讓Children對應Group?






發文: 60
積分: 0
於 2015-03-01 01:36 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位大大!
請問在CursorTreeAdapter裡,如何讓Children對應到正確的Group?

在我建構的SQLite資料庫裡,同時有book1和book2資料表,
但以下程式碼,會讓978-111-818-348-9和978-986-276-397-1同時對應到SQLite資料庫的book1資料表
而我想要讓978-111-818-348-9對應到SQLite資料庫的book1資料表,
而978-986-276-397-1對應到SQLite資料庫的book2資料表,
這有辦法做到嗎?

下面有附上
UI顯示圖、book1和book2資料表圖的連結。

以下為程式碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
public class MyCursorTreeAdapter extends CursorTreeAdapter {
 
  public MyCursorTreeAdapter(Cursor cursor, Context context) {
    super(cursor, context);
    // TODO 自動產生的建構子 Stub
  }
 
  public MyCursorTreeAdapter(Cursor cursor, Context context,
      boolean autoRequery) {
    super(cursor, context, autoRequery);
    // TODO 自動產生的建構子 Stub
  }
 
  @Override
  protected Cursor getChildrenCursor(Cursor groupCursor) {
    // TODO 自動產生的方法 Stub
    
    return groupCursor;
  }
 
  @Override
  protected View newGroupView(Context context, Cursor cursor,
      boolean isExpanded, ViewGroup parent) {
    // TODO 自動產生的方法 Stub
    LayoutInflater entryInflater = (LayoutInflater) context
         .getSystemService(context.LAYOUT_INFLATER_SERVICE);
         View view = entryInflater.inflate(R.layout.groupitem, null);
    return view;
  }
 
  @Override
  protected void bindGroupView(View view, Context context, Cursor cursor,
      boolean isExpanded) {
    // TODO 自動產生的方法 Stub
    TextView txtlogo = (TextView) view.findViewById(R.id.text_college);
    txtlogo.setText(cursor.getString(cursor.getColumnIndex("title")));
  }
 
  @Override
  protected View newChildView(Context context, Cursor cursor,
      boolean isLastChild, ViewGroup parent) {
    // TODO 自動產生的方法 Stub
     LayoutInflater entryInflater = (LayoutInflater) context
     .getSystemService(context.LAYOUT_INFLATER_SERVICE);
     View view = entryInflater.inflate(R.layout.entry, null);
    return view;
  }
 
  @Override
  protected void bindChildView(View view, Context context, Cursor cursor,
      boolean isLastChild) {
    // TODO 自動產生的方法 Stub
    ImageView imgCover = (ImageView) view.findViewById(R.id.imgCover);
    TextView txtTitle = (TextView) view.findViewById(R.id.textTitle);
    TextView txtAuthor = (TextView) view.findViewById(R.id.textAuthor);
    TextView txtIsbn = (TextView) view.findViewById(R.id.textIsbn);
    TextView txtothers = (TextView) view.findViewById(R.id.textOthers);
    txtTitle.setText(cursor.getString(cursor.getColumnIndex("title")));
    txtAuthor.setText(cursor.getString(cursor.getColumnIndex("author")));
    txtIsbn.setText(cursor.getString(cursor.getColumnIndex("isbn")));
    String misc = cursor.getString(cursor.getColumnIndex("publisher"))
        + " " + cursor.getString(cursor.getColumnIndex("year"));
    txtothers.setText(misc);
    byte[] photo = cursor.getBlob(cursor.getColumnIndex("cover"));
    Bitmap imgphoto = BitmapFactory.decodeByteArray(photo, 0, photo.length);
    imgCover.setImageBitmap(imgphoto);
  }
 
}


book1資料表圖:
http://herowing.myweb.hinet.net/book1.png

book2資料表圖:
http://herowing.myweb.hinet.net/book2.png

以下為UI顯示圖:

(縮略圖,點擊圖片鏈接看原圖)


reply to postreply to post
» JWorld@TW »  Java ME、Google Android 平台與 JavaCard 討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8