0

カスタムアダプタを使用して拡張可能なリストビューを使用して、いくつかのコードを継承しました。別のコンポーネントを使用してトリガーできるように、expandイベントが登録されている場所を特定しようとしています。Expandablelistviewにグループのリスナーが表示されません。ログのprintステートメントを使用して確認できることから、グループがクリックされたときにgetGroupView()が呼び出されます。ただし、メソッドがどこで呼び出されるか、またはどのように呼び出されるかはわかりません。

これがカスタムアダプタクラスです。

public class MyExpandableListAdapter extends BaseExpandableListAdapter {

        private String[][] teams;
        private String[] league;
        private final Context context;
        private ImageView imageViewUser;

        public MyExpandableListAdapter(String[] groups, String[][] children, Context context) {
            this.context = context;
            this.teams = children;
            this.league = groups;
        }

        public Object getChild(int groupPosition, int childPosition) {
            return teams[groupPosition][childPosition];
        }

        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }

         public int getChildrenCount(int groupPosition) {
         return teams[groupPosition].length;
         }

         public TextView getGenericView() {
             AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
             ViewGroup.LayoutParams.FILL_PARENT, 64);

             TextView textView = new TextView(context);
             textView.setLayoutParams(lp);
             textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);

             textView.setPadding(56, 0, 0, 0);
             return textView;
         }
         public boolean areAllItemsEnabled() {
                return false;
            }
         public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
             if (view == null) {
                    LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
                    view = inf.inflate(R.layout.child_row, null);
                }
             view.setFocusable(false);
             view.setClickable(false);
             TextView textView = (TextView) view.findViewById(R.id.grp_child);
             textView.setFocusable(false);
             textView.setClickable(false);
             textView.setText(getChild(groupPosition, childPosition).toString());
             //final ImageView imageView;
             //imageView = (ImageView) view.findViewById(R.id.imageViewChild);
            // imageView.setImageResource(android.R.drawable.ic_menu_gallery);
             //imageView.setTag(new ChildPosition(groupPosition,childPosition));
             //imageView.setOnClickListener(new OnClickListener(){

                    /*public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        ChildPosition realPosition = (ChildPosition) imageView.getTag();
                        Log.d("Shimmer","Click" + "position: " + realPosition.mGroupPosition + " " + realPosition.mChildPosition);
                    }

                 });*/
             return view;
         }

         public Object getGroup(int groupPosition) {
             System.out.println("Group Clicked!S");

         return league[groupPosition];
         }

         public int getGroupCount() {
         return league.length;
         }

         public long getGroupId(int groupPosition) {
         return groupPosition;
         }

         public View getGroupView(int groupPosition, boolean isExpanded,View view, ViewGroup parent) {
             //TextView textView = getGenericView();

             System.out.println("I AM HERE!!!!");

             if (view == null) {
                    LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
                    view = inf.inflate(R.layout.group_row, null);
                }
             TextView textView = (TextView) view.findViewById(R.id.row_name);
             textView.setText(getGroup(groupPosition).toString());
             final ImageView imageView;
             imageView = (ImageView) view.findViewById(R.id.imageView1);
             imageView.setImageResource(R.drawable.expand);
             imageView.setFocusable(false);
             imageView.setClickable(true);
             imageView.setTag(groupPosition);

             imageViewUser = (ImageView) view.findViewById(R.id.usericon);
             imageViewUser.setImageResource(R.drawable.user_one);

        /*   if (view == null) {
                    LayoutInflater inf = (LayoutInflater) this.getSystemService(this.LAYOUT_INFLATER_SERVICE);
                    view = inf.inflate(R.layout.expandlist_group_item, null);
                }*/


return view;
         }

public boolean isChildSelectable(int groupPosition, int childPosition) {
         return true;
         }
         public boolean hasStableIds() {
         return true;
         }


    }
4

1 に答える 1

0

次のように、グループのクリックをシミュレートしようとしましたか?

groupView.performClick();

?

編集:

public View getGroupView(int groupPosition, boolean isExpanded,View view, ViewGroup parent) {
    System.out.println("I AM HERE!!!!");

    ...

    if (groupPosition == thePositionIWantToAutomaticallyExpend) {
        view.post(new Runnable() {
             @Override
             public void run() {
                view.performClick(); // This will simulate a user clicking on the view
             }
        });
    }
}
于 2012-11-07T09:22:02.083 に答える