PopUp内的ExpandableListView [英] ExpandableListView inside PopUp

查看:63
本文介绍了PopUp内的ExpandableListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i've read some question about this..i've tried all what they suggested but still, i have java null pointer.... here is my main code

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>

希望有人注意到我的错,我会解决

wish somebody notice my fault and i'll fix it

推荐答案

buttonELVKelamin从未初始化,因此在设置点击侦听器时为null.

buttonELVKelamin is never initialized so it is null when you set your click listener.

这篇关于PopUp内的ExpandableListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆