-3

I am trying to create a dialog box with Textview in android like:

Image]

For creating the Textview, I am using following function object.settype(textviewobject) but there is no success.

halfer
  • 19,824
  • 17
  • 99
  • 186
Developer_99
  • 135
  • 1
  • 7
  • 17

5 Answers5

2
            final Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.dialog);
            TextView text1 = 
                      (TextView)dialog.findViewById(R.id.text1);
            Button proceed =
            (Button)dialog.findViewById(R.id.button);

            proceed.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                   dialog.dismiss();

                }
            });

            dialog.show();

dialog.xml

    <?xml version="1.0" encoding="utf-8"?>
     <RelativeLayout   
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical" 
       android:layout_width="match_parent"
       android:layout_height="match_parent">

<TextView
    android:id="@+id/text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text1"
    android:layout_centerInParent="true"/>

  <Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:text="Proceed"
    android:layout_alignParentBottom="true"/>


 </RelativeLayout>

I hope this helps

Abhishek Jaiswal
  • 628
  • 6
  • 17
1

Use this:-

    private void fn_showAlertDialog() {
        new AlertDialog.Builder(YourActivity.this)
            .setTitle("Title of your dialog")
            .setMessage("Text that you want to show.")
            .setCancelable(false)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    //do your task
                    dialog.cancel();
                }
            })
            .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    //do your task
                    dialog.cancel();
                }
            })
            .setIcon(android.R.drawable.ic_dialog_alert)
            .show();
}
priyanka kataria
  • 417
  • 5
  • 17
0

Use alertdialog like this, and create another layout for dialog:

final AlertDialog.Builder builder = new AlertDialog.Builder(context);
                LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                @SuppressLint("InflateParams") final View alertlayout = inflater.inflate(R.layout.notif_msg_dialog, null);

                TextView text_main=(TextView)alertlayout.findViewById(R.id.notif_msg);
                text_main.setText("YOUR TEXT");


                builder.setView(alertlayout);
                packsizeDialog=builder.create();
                packsizeDialog.show();

Here, notif_msg_dialog.xml is layout which has textview

Divyesh Patel
  • 2,576
  • 2
  • 15
  • 30
0

Just use AlertDialog.Builder and put your text in setMessage it will display

        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setMessage("your text");
        builder.create();
        builder.show();
Saurabh Padwekar
  • 3,888
  • 1
  • 31
  • 37
0

You can get help from following post http://stackoverflow.com/questions/10903754/input-text-dialog-android

singh.indolia
  • 1,292
  • 13
  • 26