2

都市の展開可能なリスト ビューを作成していますが、展開しません。私はこれとほぼ同じものをもう1つ持っていますが、これは拡大しません。何が問題なのかを確認するのに多くの時間を費やしました。これ以上無駄にする余裕はありません。誰か問題を指摘してもらえますか?

expandGroup(0) も呼び出しましたが、まだ展開されていません (展開するものが何もないかのように)。

XML

<ExpandableListView
                        android:id="@+id/judet"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="10dp"
                        android:choiceMode="singleChoice"
                        android:groupIndicator="@null"
                        android:smoothScrollbar="true" >
                    </ExpandableListView>

私のメインクラスで

final AdapterJudet adapterJudet = new AdapterJudet(getApplicationContext());
ExpandableListView judet = (ExpandableListView) findViewById(R.id.judet);
judet.setAdapter(adapterJudet);
judet.setOnChildClickListener(new OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {

                AdapterJudet.selected = AdapterJudet.judete[childPosition];
                judet.collapseGroup(0);
                return false;
            }
        });

アダプタ クラス

public class AdapterJudet extends BaseExpandableListAdapter {

    Context ctx;
    static String [] judete = {"Alba","Arad","Arges","Bacau","Bihor","Bistrita-Nasaud","Botosani","Brasov","Braila","Buzau","Caras-Severin","Cluj","Constanta","Covasna","Dambovita","Dolj","Galati","Giurgiu","Gorj","Hargita","Hunedoara","Ialomita","Maramures","Mehedinti","Mures","Neamt","Olt","Prahova","Satu-Mare","Salaj","Sibiu","Teleorman","Timis","Tulcea","Valcea","Vaslui","Vrancea","Bucuresti","Ilfov","Calarasi","Iasi","Suceava"};
    static String selected = "Judet";
    static int judetID = -1;

    public AdapterJudet (Context ctx){
        this.ctx = ctx;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View v = convertView;

        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.item_layout, parent, false);
        }

        TextView itemName = (TextView) v.findViewById(R.id.itemName);

        itemName.setText(judete[childPosition]);
        judetID = childPosition;
        return v;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        // TODO Auto-generated method stub
        return judete.length;
    }

    @Override
    public Object getGroup(int groupPosition) {
        // TODO Auto-generated method stub
        return groupPosition;
    }

    @Override
    public int getGroupCount() {
        // TODO Auto-generated method stub
        return 1;
    }

    @Override
    public long getGroupId(int groupPosition) {
        // TODO Auto-generated method stub
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View v = convertView;

        if (v == null) {
            LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.group_layout, parent, false);
        }

        TextView groupName = (TextView) v.findViewById(R.id.groupName);

        groupName.setText(selected);

        return v;
    }

    @Override
    public boolean hasStableIds() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        // TODO Auto-generated method stub
        return true;
    }

}
4

5 に答える 5

3

あなたのためにそれを使用してくださいExpandableListView

list.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return  list.isGroupExpanded(groupPosition) ? list.collapseGroup(groupPosition) : list.expandGroup(groupPosition);
            }
        });
于 2016-05-12T12:41:19.780 に答える