Using onClick attribute in layout xml causes a NoSuchMethodException in Android dialogs

后端 未结 9 1684
说谎
说谎 2020-11-29 07:45

I have created a custom dialog and a layout xml:




        
9条回答
  •  星月不相逢
    2020-11-29 08:23

    Define the method (dialogClicked) in Activity. And modify TestDialog like the following code:

    public class TestDialog extends Dialog {
     Context mContext;
     public TestDialog(final Context context)
     {
    
      super(context);
      mContext=context;
     }
    
     @Override
     protected void onCreate(final Bundle savedInstanceState)
     {
      super.onCreate(savedInstanceState);
      LinearLayout ll=(LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.dialog, null);
      setContentView(ll); 
     }
    }
    

    I think it works :)

提交回复
热议问题