1

私はアンドロイドアプリケーションを開発しています。これまでのところ動作します。私は1つの場所でCursorTreeAdapterを使用しています。 CursorTreeAdapter内のグループにボタンを追加する必要があります。私は簡単にtextviewを追加することができますが、私はボタンを追加すると、私のリストdoesnt仕事。それは拡大しません。ボタンを正しく追加するにはどうしたらいいですか?可能であれば、いくつかのコード例を教えてください。私はこれらの2つの機能を変更しようとしましたが、xml gorupファイルにボタンを追加すると、リストが拡大しません。AndroidアプリでCursorTreeAdapterのすべてのグループにボタンを追加すると(ダイアログメニューが開きます)

@Override 
    protected void bindGroupView(View view, Context context, Cursor cursor, 
      boolean isExpanded) { 
     TextView text_line1 = (TextView) view 
       .findViewById(R.id.work_list_group_view); 
     text_line1.setText("title1"); 

     TextView text_line2 = (TextView) view 
       .findViewById(R.id.work_list_group_view2); 
     text_line2.setText("title2"); 

     ImageButton button = (ImageButton) view.findViewById(R.id.context_menu_button); 


    } 

    @Override 
    public View newGroupView(Context context, Cursor cursor, 
      boolean isExpanded, ViewGroup parent) { 
     return getLayoutInflater().inflate(
       R.layout.work_list_expandable_group, parent, false); 
    } 

答えて

0
protected void bindGroupView(View view, Context context, Cursor cursor, 
          boolean isExpanded) { 
    TextView text_line1 = (TextView) view 
      .findViewById(R.id.work_list_group_view); 
    text_line1.setText("title1"); 

    text_line1.setOnClickListener(new View.OnClickListener() { 
     // Open your dialog here 
    }); 

    TextView text_line2 = (TextView) view 
      .findViewById(R.id.work_list_group_view2); 
    text_line2.setText("title2"); 

    ImageButton button = (ImageButton) view 
       .findViewById(R.id.context_menu_button); 
} 
0
@Override 
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) { 
    TextView text_line1 = (TextView) view.findViewById(R.id.work_list_group_view); 
    text_line1.setText("title1"); 

    TextView text_line2 = (TextView) view.findViewById(R.id.work_list_group_view2); 
    text_line2.setText("title2"); 

    ImageButton button = (ImageButton) view.findViewById(R.id.context_menu_button); 
    // Magic comes here, you should add: 
    button.setFocusable(false); // ListItem is not clickable if it has focusable child's. 
    button.setOnClickListener(new OnClickListener(){ ... }); 

} 

@Override 
public View newGroupView(Context context, Cursor cursor, 
     boolean isExpanded, ViewGroup parent) { 
    return getLayoutInflater().inflate(R.layout.work_list_expandable_group, parent, false); 
} 
関連する問題