PopUp中的ExpandableListView

时间:2014-04-02 03:12:58

标签: android expandablelistview popupwindow

我已经读过一些关于这个的问题..我已经尝试了所有他们的建议但是,我还有java空指针.... 这是我的主要代码

public class DaftarAkun extends Activity {
    TextView tekserror;
    EditText password1;
    EditText username;
    EditText password2;
    ImageButton buttonELVKelamin;
    ImageButton buttonELVAktivitas;
    // EditText email;
    ExpandableListAdapter exListAdapterKelamin;
    List<String> listDataHeaderKelamin;
    HashMap<String, List<String>> listDataChildKelamin;
    ExpandableListAdapter exListAdapterAktivitas;
    List<String> listDataHeaderAktivitas;
    HashMap<String, List<String>> listDataChildAktivitas;
    Context thisContext = this;


    protected void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);
        setContentView(R.layout.daftar_akun);
        buttonELVKelamin.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                ExpandableListView exListViewKelamin;
                final Dialog dialog = new Dialog(thisContext);
                dialog.setContentView(R.layout.pop_up_daftar_akun_elvkelamin);
                dialog.setTitle("Jenis Kelamin");
                LayoutInflater li = (LayoutInflater) getBaseContext()
                        .getSystemService(LAYOUT_INFLATER_SERVICE);
                View popupKelamin = li.inflate(
                        R.layout.pop_up_daftar_akun_elvkelamin, null);
                dialog.setContentView(v);
                // get the listview
                exListViewKelamin = (ExpandableListView) popupKelamin
                        .findViewById(R.id.exLVKelamin);
                prepareListDataKelamin();

                exListAdapterKelamin = new com.ta.helper.ExpandableListAdapter(
                        DaftarAkun.this, listDataHeaderKelamin,
                        listDataChildKelamin);
                exListViewKelamin.setAdapter(exListAdapterKelamin);
                exListViewKelamin
                        .setOnChildClickListener(new OnChildClickListener() {

                            @Override
                            public boolean onChildClick(
                                    ExpandableListView parent, View v,
                                    int groupPosition, int childPosition,
                                    long id) {
                                // TODO Auto-generated method stub
                                return false;
                            }
                        });
                WindowManager.LayoutParams params = dialog.getWindow()
                        .getAttributes();
                params.gravity = Gravity.TOP | Gravity.LEFT;
                params.y = 80;
                dialog.getWindow().setAttributes(params);
                // dialog width and height.
                dialog.getWindow().setLayout(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);

            }

            private void prepareListDataKelamin() {
                listDataHeaderKelamin = new ArrayList<String>();
                listDataChildKelamin = new HashMap<String, List<String>>();

                // Adding child data
                listDataHeaderKelamin.add("Jenis Kelamin");
                // Adding child data
                List<String> kelamin = new ArrayList<String>();
                kelamin.add("Pria");
                kelamin.add("Wanita");
                listDataChildKelamin.put(listDataHeaderKelamin.get(0), kelamin);// Header,
                                                                                // Child
                                                                                // data

            }
        });

这是我的主要xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#99cc00"
    android:scrollbarSize="1dp" >


        <ImageButton
            android:id="@+id/buttonLVKelamin"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="9dp"
            android:layout_marginLeft="26.5dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="9dp"
            android:background="#00000000"
            android:src="@drawable/registrasi_hdpi_24" />


        <ImageButton
            android:id="@+id/buttonLVAktivitas"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginLeft="26.5dp"
            android:layout_marginRight="25dp"
            android:layout_marginTop="9dp"
            android:background="#00000000"
            android:src="@drawable/registrasi_hdpi_24" />


</ScrollView>

这是我的弹出窗口xml

<?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="match_parent"
    android:orientation="vertical" >

    <ExpandableListView
        android:id="@+id/exLVKelamin"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ExpandableListView>

</LinearLayout>
希望有人注意到我的错,我会解决它

1 个答案:

答案 0 :(得分:0)

buttonELVKelamin永远不会被初始化,所以当您设置点击监听器时它是null