我需要哪个方面? [英] Which context do i need?

查看:111
本文介绍了我需要哪个方面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个对话框,并使用(本)心不是工作。到现在为止,它只是是一个按钮呼叫被叫DialogBox的内DialogBox的,但现在该按钮需要调用另一个对话框。对话框dialogdelcon是一个有问题的。

下面是code:

 情况下R.id.delappt:
        // rmvall();        最后一个对话框dialogdelsel =新的对话框(本);
           dialogdelsel.setContentView(R.layout.delsel);
           dialogdelsel.setTitle(你想怎么办?);
           dialogdelsel.setCancelable(真);          按钮btndelsel =(按钮)dialogdelsel.findViewById(R.id.btndelsel);
          btndelsel.setOnClickListener(新OnClickListener(){
               @覆盖
               公共无效的onClick(视图v){
                   //此处删除所选的code。               }
           });         按钮btndelall =(按钮)dialogdelsel.findViewById(R.id.btndelall);
          btndelall.setOnClickListener(新OnClickListener(){
               @覆盖
               公共无效的onClick(视图v){
                   //此处删除所有code。
                  最后一个对话框dialogdelcon =新的对话框();
                   dialogdelcon.setContentView(R.layout.delcon);
                   dialogdelcon.setTitle(删除确认);
                   dialogdelcon.setCancelable(真);                  按钮buttoncnclok =(按钮)dialogdelcon.findViewById(R.id.btndelcon);
                   buttoncnclok.setOnClickListener(新OnClickListener(){                    //在点击取消按钮
                       @覆盖
                       公共无效的onClick(视图v){
                           dialogdelcon.dismiss();
                       }
                   });                 dialogdelcon.show();
               }
           });
        dialogdelsel.show();
        打破;


解决方案

getApplicationContext()或使用 YourActictyName.this 由于这个指按钮点击听者,而不是你的类对象

I'm creating a dialog box and using the (this) isnt working. Up until now its just been a button calling a dialogbox but now the button within the called dialogbox needs to call another dialog. The Dialog dialogdelcon is the one with problem.

Here is the code:

case R.id.delappt:
        //rmvall();

        final Dialog dialogdelsel = new Dialog(this);
           dialogdelsel.setContentView(R.layout.delsel);
           dialogdelsel.setTitle("What would you like to do?");
           dialogdelsel.setCancelable(true);

          Button btndelsel = (Button) dialogdelsel.findViewById(R.id.btndelsel);
          btndelsel.setOnClickListener(new OnClickListener() {


               @Override
               public void onClick(View v) {
                   // delete selected code here.

               }
           });

         Button btndelall = (Button) dialogdelsel.findViewById(R.id.btndelall);
          btndelall.setOnClickListener(new OnClickListener() {


               @Override
               public void onClick(View v) {
                   // delete all code here.
                  final Dialog dialogdelcon = new Dialog();
                   dialogdelcon.setContentView(R.layout.delcon);
                   dialogdelcon.setTitle("Deletion Confirmation");
                   dialogdelcon.setCancelable(true);

                  Button buttoncnclok = (Button) dialogdelcon.findViewById(R.id.btndelcon);
                   buttoncnclok.setOnClickListener(new OnClickListener() {

                    // on click for cancel button
                       @Override
                       public void onClick(View v) {
                           dialogdelcon.dismiss();
                       }
                   });

                 dialogdelcon.show();
               }
           });


        dialogdelsel.show();
        break;

解决方案

getApplicationContext() or use YourActictyName.this Because this refers the button click listner ,not your class Object

这篇关于我需要哪个方面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆