Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
43 views
in Technique[技术] by (71.8m points)

java - Creating Button inside expandableListView item, and fix one list which does not open

i have question, and problem, the question is, i need to create a button next to text.. example : when you open Keys 0-9 and C in level 0 and see scancode 11,keylevel = 0, i need button after the =. and my the problem is, i cant open the second group of expandableListView.. check my code below thanks.

ActivityMain

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#6f767b"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/Header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/headline_backcolor"
        android:divider="@color/colorACD_orange"
        android:dividerHeight="20dp"
        android:fontFamily="@font/sourcesanspro_bold"
        android:padding="10dp"
        android:text="@string/acd_keyconfig"
        android:textAlignment="viewStart"
        android:textColor="@color/headline_textcolor"
        android:textSize="20sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <LinearLayout
        android:id="@+id/line"
        android:layout_width="wrap_content"
        android:layout_height="7dp"
        android:layout_below="@id/Header"
        android:layout_alignLeft="@+id/Header"
        android:layout_alignRight="@+id/Header"
        android:background="@color/colorACD_orange"
        android:orientation="horizontal" />

        
    <ExpandableListView
        android:id="@+id/lvExp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/line"
        android:layout_alignParentBottom="false"
        android:divider="@color/colorACD_orange"
        android:dividerHeight="3dp">


    </ExpandableListView>


</RelativeLayout> 

list_group

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="#d2d4d5 ">


    <TextView
        android:id="@+id/lblListHeader"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
        android:textSize="18dp"
        android:textColor="@color/colorACD_lightgray1"
        android:background="#d2d4d5"
        android:fontFamily="@font/sourcesansproregular"
        />



</LinearLayout>

list_item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:orientation="vertical"
    android:background="#d2d4d5 "
    android:fontFamily="@font/sourcesansproregular">

    <TextView
        android:id="@+id/lblListItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:fontFamily="@font/sourcesanspro_bold"
        android:textColor="@color/colorACD_gray"
        android:layout_margin="9dp"
        android:layout_marginLeft="5dp">
    </TextView>

    <LinearLayout
        android:id="@+id/line"
        android:layout_width="391dp"
        android:layout_height="10dp"
        android:orientation="horizontal" />

</LinearLayout>

MainActivity

package com.example.test;

import android.os.Bundle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;

import android.widget.ExpandableListView;


public class MainActivity extends Activity {

    ExpandableListAdapter listAdapter;
    ExpandableListView expListView;
    List<String> listDataHeader;
    HashMap<String, List<String>> listDataChild;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        // get the listview
        expListView = (ExpandableListView) findViewById(R.id.lvExp);

        // preparing list data
        prepareListData();

        listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);

        // setting list adapter
        expListView.setAdapter(listAdapter);
    }

    /*
     * Preparing the list data
     */
    private ExpandableListView prepareListData() {
        listDataHeader = new ArrayList<String>();
        listDataChild = new HashMap<String, List<String>>();

        // Adding child data
        listDataHeader.add("Keys 0-9 and C in level 0");
        listDataHeader.add("Keys 0-9 and C in level 1");
        listDataHeader.add("Keys 1 and C in level 2");
        listDataHeader.add("Keys Fn, Up, Down, S and Enter without level information");

        // Adding child data
        List<String> K09C0 = new ArrayList<String>();
        K09C0.add("scancode 11, keylevel 0 =");
        K09C0.add("scancode 2, keylevel 0 =");
        K09C0.add("scancode 3, keylevel 0 =");
        K09C0.add("scancode 4, keylevel 0 =");
        K09C0.add("scancode 5, keylevel 0 =");
        K09C0.add("scancode 6, keylevel 0 =");
        K09C0.add("scancode 7, keylevel 0 =");
        K09C0.add("scancode 8, keylevel 0 =");
        K09C0.add("scancode 9, keylevel 0 =");
        K09C0.add("scancode 10, keylevel 0 =");
        K09C0.add("scancode 14, keylevel 0 =");
        // Adding child data
        List<String> K09C1 = new ArrayList<String>();
        K09C0.add("scancode 11, keylevel 1 =");
        K09C0.add("scancode 2, keylevel 1 =");
        K09C0.add("scancode 3, keylevel 1 =");
        K09C0.add("scancode 4, keylevel 1 =");
        K09C0.add("scancode 5, keylevel 1 =");
        K09C0.add("scancode 6, keylevel 1 =");
        // Adding child data
        List<String> K1C2 = new ArrayList<String>();
        K1C2.add("scancode 2, keylevel 2 =");
        K1C2.add("scancode 14, keylevel 0 =");
        // Adding child data
        List<String> Keys = new ArrayList<String>();
        Keys.add("scancode 672 =");
        Keys.add("scancode 103 =");
        Keys.add("scancode 108 =");
        Keys.add("scancode 656 =");

        listDataChild.put(listDataHeader.get(0), K09C0); // Show list for Keys 0-9 and C in level 0
        listDataChild.put(listDataHeader.get(1), K09C1); // Show list for Keys 0-9 and C in level 1
        listDataChild.put(listDataHeader.get(2), K1C2);  // Show list for Keys 0-9 and C in level 2
        listDataChild.put(listDataHeader.get(3), Keys);  // Show list for Keys 0-9 and C in level Keys,Fn.Up,Down
        return expListView;
    }


}

ExpandableListAdapter

package com.example.test;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter {

    private Context _context;
    private List<String> _listDataHeader; // header titles
    // child data in format of header title, child title
    private HashMap<String, List<String>> _listDataChild;

    public ExpandableListAdapter(Context context, List<String> listDataHeader,
                                 HashMap<String, List<String>> listChildData) {
        this._context = context;
        this._listDataHeader = listDataHeader;
        this._listDataChild = listChildData;
    }


    @Override
    public Object getChild(int groupPosition, int childPosititon) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .get(childPosititon);
    }

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

    @Override
    public View getChildView(int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_item, null);
        }

        TextView txtListChild = (TextView) convertView
                .findViewById(R.id.lblListItem);

        txtListChild.setText(childText);
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return this._listDataChild.get(this._listDataHeader.get(groupPosition))
                .size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return this._listDataHeader.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        return this._listDataHeader.size();
    }

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

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                             View convertView, ViewGroup parent) {
        String headerTitle = (String) getGroup(groupPosition);
        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this._context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.list_group, null);
        }

        TextView lblListHeader = (TextView) convertView
                .findViewById(R.id.lblListHeader);
        lblListHeader.setTypeface(null, Typeface.BOLD);
        lblListHeader.setText(headerTitle);

        return convertView;
    }

    @Override
    public boolean has

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

547k answers

4 comments

35.3k users

...