首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ExpandableListView内部PopUp

ExpandableListView内部PopUp
EN

Stack Overflow用户
提问于 2014-04-02 03:12:57
回答 1查看 989关注 0票数 1

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

代码语言:javascript
复制
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

代码语言:javascript
复制
<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

代码语言:javascript
复制
<?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>

希望有人注意到我的错,我会弥补的

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-02 03:24:56

buttonELVKelamin从未初始化过,所以当您设置单击侦听器时,它就是null

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22800836

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档