【问题标题】:Trouble with OnClick , LayoutInflater, and AlertDialogOnClick 、 LayoutInflater 和 AlertDialog 的问题
【发布时间】:2013-06-27 10:42:32
【问题描述】:

我有一个打开的 onClick 事件和一个用 LayoutInflater 充气的 AlertDialog。我可以单击膨胀的 AlertDialog 中的一个按钮,然后求解一个方程。问题是这个 OnClick 没有响应,就像什么都没有发生一样。有谁知道为什么?

编辑现在屏幕变暗了,我可以告诉我不再在同一个活动中,因为屏幕没有响应,但视图仍然是原始页面。按下后退按钮使屏幕再次变亮并响应。

lay1.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v)        
        {                     

            LayoutInflater myLayout = LayoutInflater.from(context);
            final View dialogView = myLayout.inflate(R.layout.alerthelp, null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            context);


            final AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialogBuilder.setView(dialogView);
            Button button1 = (Button) dialogView.findViewById(R.id.button1);
            button1.setOnClickListener(new OnClickListener(){


            public void onClick(View v) {
                TextView stax1=(TextView)alertDialog.findViewById(R.id.salestax);
                String sax1 = stax1.getText().toString();
                double sx1 = Double.parseDouble(sax1);

                TextView textviewlay1 =(TextView)alertDialog.findViewById(R.id.m1ab);
                String stringl1 = textviewlay1.getText().toString();
                 Double doubl1 = Double.parseDouble(stringl1);  

                TextView textviewp1 = (TextView)alertDialog.findViewById(R.id.inputPrice);
                String stringp1 = textviewp1.getText().toString();
                Double intp1 = Double.parseDouble(stringp1);

                double resultl1 = intp1 - (doubl1*sx1);
                int precision21t = 100; //keep 4 digits
                resultl1= Math.floor(resultl1 * precision21t +.5)/precision21t;
                textViewtotalproduct.setText(String.valueOf(resultl1));     
}); 

 alertDialog.show();
        return true;    




        }});

【问题讨论】:

  • R.layout.alerthelp 绝对存在于布局文件夹中。我可以打开它,看到所有的按钮,每个按钮的拼写都是正确的,没有一个是大写的。

标签: android button android-alertdialog onclicklistener layout-inflater


【解决方案1】:

您正在返回false,这意味着长按没有发生。所以请返回true,以便您的长按生效。

您还需要致电alertDialog.show(); 以打开它,回答您的第二个问题。

【讨论】:

  • 现在我从 onclick 中得到震动,仅此而已。无论如何谢谢你
  • 我该怎么做?我是这个东西的3个月大的婴儿。 :)
  • 这很有趣。也许我把这个放在错误的地方。我整晚都在这。我把它放在 return true 行之前,现在 onClick 会振动,然后屏幕会稍微变暗,但它不会打开 alertdialog。
  • 试着把“alertDialogBu​​ilder.setView(dialogView);”就在您创建 alertDialog 之前。
  • 我很高兴能帮助 m8 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 1970-01-01
  • 2011-10-17
相关资源
最近更新 更多