-2

My screenshot and code follows.the app crashes When i input all the info and press save details button !

Can anyone help to solve it ?

And one more question: i need this dialog box later to insert it in each of my list view. Is that difficult ?

enter image description here

when i write all the info i want and press save details the app crashes! Can anyone help?

Here is my code too: `

package com.example.user.dialogbox;

import android.app.Activity;
import android.app.Dialog;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends Activity{

    Button btn_details;
    TextView textDialog1;
    TextView textDialog2;
    TextView textDialog3;
    TextView textDialog4;

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

        textDialog1 = (TextView)findViewById(R.id.text1 );
        textDialog2 = (TextView)findViewById(R.id.text2);
        textDialog3 = (TextView)findViewById(R.id.text3);
        textDialog4 = (TextView)findViewById(R.id.text4);

        btn_details = (Button)findViewById(R.id.button_details);
        btn_details.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {


                showCustomDialog(textDialog1);
                showCustomDialog(textDialog2);
                showCustomDialog(textDialog3);
                showCustomDialog(textDialog4);
            }
        });



    }

    protected void showCustomDialog(final TextView _textDialog) {

        final Dialog dialog = new Dialog(MainActivity.this);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.customdialog);

        final EditText edit1 = (EditText)dialog.findViewById(R.id.edit1);
        final EditText edit2 = (EditText)dialog.findViewById(R.id.edit2);
        final EditText edit3 = (EditText)dialog.findViewById(R.id.edit3);
        final EditText edit4 = (EditText)dialog.findViewById(R.id.edit4);

        final TextView text1 = (TextView)dialog.findViewById(R.id.text1);
        final TextView text2 = (TextView)dialog.findViewById(R.id.text2);
        final TextView text3 = (TextView)dialog.findViewById(R.id.text3);
        final TextView text4 = (TextView)dialog.findViewById(R.id.text4);

        Button button = (Button)dialog.findViewById(R.id.button1);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                _textDialog.setText(edit1.getText().toString());
                _textDialog.setText(edit2.getText().toString());
                _textDialog.setText(edit3.getText().toString());
                _textDialog.setText(edit4.getText().toString());

                _textDialog.setText(text1.getText().toString());
                _textDialog.setText(text2.getText().toString());
                _textDialog.setText(text3.getText().toString());
                _textDialog.setText(text4.getText().toString());

                dialog.dismiss();
            }
        });

        dialog.show();
    }

}
Anoop M Maddasseri
  • 8,060
  • 3
  • 40
  • 61
Ntina.Tsif
  • 51
  • 9
  • Why you calling the `showCustomDialog` method repeatedly on button click.well , that is not a good approach.you may need to post the error log. – Anoop M Maddasseri Jul 31 '15 at 10:53

1 Answers1

0

The problem is that you trying to display a lot of dialogs at once which is not good try to display one Dialog that contains all the views you want to display :)

insert values from the dialog to a Listview its not difficult you can Store the values into a temporary list like ArrayList then you can fill the listview :)

this link will help you :

Populating a ListView using an ArrayList?

Community
  • 1
  • 1
Mohammad Salem
  • 953
  • 7
  • 15