单击文本必须打开一个对话框

时间:2014-02-05 05:40:25

标签: android dialog

我想在点击文本时打开一个对话框,就像我点击android一样,必须打开一个对话框,并且在该对话框中给出了关于android的所有描述,就像我想要它的应用程序一样,那么什么我该怎么做,请帮忙, 提前谢谢......

这是我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

3 个答案:

答案 0 :(得分:4)

您在dialog.show();之外致电OnClickListener(..)

您的代码应该是这样的。

 tvaboutwebapp.setOnClickListener(new View.OnClickListener() {

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

答案 1 :(得分:1)

Dialog事件中显示TextView onClick()

tvaboutwebapp.setOnClickListener(new View.OnClickListener() {

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

答案 2 :(得分:0)

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();


}

  }