akky777
akky777

Reputation: 423

click on text a dialog box must open

i want to open a dialog box on click on text, like if i click on android a dialog box must open and all discription is given about android in that dialog box, same as that i want it for my app, so what shoul i do, please help, thanks in advance......

this is my code for dialog box :

 public void webapp(View V)
       {
            final Dialog dialog = new Dialog(Aboutus.this);
            dialog.setContentView(R.layout.activity_web_app);
            dialog.setTitle("WebApp");

            tvaboutwebapp=(TextView)dialog.findViewById(R.id.tvaboutwebapp);

            // Set On ClickListener
            tvaboutwebapp.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                }
            });

            dialog.show();
       }

enter image description here

Upvotes: 1

Views: 3714

Answers (3)

Palak
Palak

Reputation: 574

Try This
 public class MainActivity extends Activity {
 TextView  tvaboutwebapp;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tvaboutwebapp=(TextView)findViewById(R.id.helloword);

       // Set On ClickListener
       tvaboutwebapp.setOnClickListener(new View.OnClickListener() {

           public void onClick(View v) {
               Showdialog();
           }
       });

     //  dialog.show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
void Showdialog()
{
    LayoutInflater li = LayoutInflater.from(MainActivity.this);
    View promptsView = li.inflate(R.layout.demo, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            MainActivity.this);
    alertDialogBuilder.setTitle("Alert!");
    // set prompts.xml to alertdialog builder
    alertDialogBuilder.setView(promptsView);

    final TextView txt = (TextView) promptsView
            .findViewById(R.id.textView1);


    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK",new               DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int id) {

                        }
                    })
            .setNegativeButton("Cancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int id) {
                            dialog.cancel();
                        }
                    });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();


}

  }

Upvotes: 0

M D
M D

Reputation: 47817

Show Dialog on TextView onClick() event:

tvaboutwebapp.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            dialog.show();
        }
    });

Upvotes: 1

Chirag Ghori
Chirag Ghori

Reputation: 4231

You call dialog.show(); outside OnClickListener(..).

Your code should be like this.

 tvaboutwebapp.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                dialog.show();
            }
        });

Upvotes: 4

Related Questions