Search code examples
androiddialogcustomdialog

unable to add array list in custom dialog


I want to add array list in custom dialog but it show's error in array adapter(R.layout.simple_list_item_1) also i changed to R.layout.simple_list_item_1 but it's not working. I have posted my code below.

dobtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                docustomdiaog();

            }

            private void docustomdiaog() 
            {
                // TODO Auto-generated method stub
                final Dialog dialog=new Dialog(Doyouwant.this);

                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

                dialog.setContentView(R.layout.dodialog);

                listdata=(ListView)dialog.findViewById(R.id.dclistView1);

                dsavebtn=(Button)dialog.findViewById(R.id.dcsave);

                dokbtn=(Button)dialog.findViewById(R.id.dcok);



                arylistdata=new ArrayList<String>();

                adpater=new ArrayAdapter<String>(this,R.layout.simple_list_item_1, arylistdata);

                dsavebtn.setOnClickListener(new OnClickListener() {


                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        addtolist=customtxt.getText().toString();

                        arylistdata.add(addtolist);

                        listdata.setAdapter(adpater);


                        dialog.dismiss();
                    }
                });

                dokbtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        dialog.dismiss();
                    }
                });
                dialog.show();
            }

        });

Solution

  • Change this

    adpater=new ArrayAdapter<String>(this,R.layout.simple_list_item_1, arylistdata);
    

    as

    adpater=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, arylistdata);