Using LayoutInflater and AlertDialog

℡╲_俬逩灬. 提交于 2019-12-06 17:01:30

It seems you are trying to load text from static TextView. May be it should be EditText?

TextView stax1=(TextView)dialogView.findViewById(R.id.xxx);
String sax1 = stax1.getText().toString();

EDITED:

Try this code:

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);
            alertDialogBuilder.setView(dialogView);

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

            public void onClick(View v) {
                TextView stax1=(TextView)dialogView.findViewById(R.id.xxx);
                String sax1 = stax1.getText().toString();
                double sx1 = Double.parseDouble(sax1);
                TextView textviewlay1 =(TextView)dialogView.findViewById(R.id.m1ab);
                String stringl1 = textviewlay1.getText().toString();
                 Double doubl1 = Double.parseDouble(stringl1);      
                TextView textviewp1 = (TextView)dialogView.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));     

            }
        }); 

 return false;  




        }});

Change

TextView stax1=(TextView)findViewById(R.id.xxx);

to

TextView stax1=(TextView)dialogView.findViewById(R.id.xxx);

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!