Android OnClick、LayoutInflater和AlertDialog出现问题
我有一个onClick事件,它打开并警告对话框,该对话框用LayoutInflater充气。我可以点击对话框中的一个按钮,就可以解出一个方程。问题是这个OnClick没有响应,因为什么都没有发生。有人知道为什么吗 现在编辑屏幕变暗,我可以告诉你我不再参与相同的活动,因为屏幕没有响应,但视图仍然是原始页面。按下“后退”按钮,屏幕再次明亮且响应迅速Android OnClick、LayoutInflater和AlertDialog出现问题,android,button,android-alertdialog,onclicklistener,layout-inflater,Android,Button,Android Alertdialog,Onclicklistener,Layout Inflater,我有一个onClick事件,它打开并警告对话框,该对话框用LayoutInflater充气。我可以点击对话框中的一个按钮,就可以解出一个方程。问题是这个OnClick没有响应,因为什么都没有发生。有人知道为什么吗 现在编辑屏幕变暗,我可以告诉你我不再参与相同的活动,因为屏幕没有响应,但视图仍然是原始页面。按下“后退”按钮,屏幕再次明亮且响应迅速 lay1.setOnLongClickListener(new OnLongClickListener() { public boole
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;
}});
您返回的是
false
,这意味着长时间单击没有发生。因此,返回true
,以便长时间单击工作
您还需要调用
alertDialog.show()
要打开它,请回答第二个问题。R.layout.alerthelp绝对存在于layout文件夹中。我可以打开它,看到所有的按钮,每个按钮的拼写都是正确的,没有一个是大写的。现在我从onclick中得到一个震动,但就是这样。无论如何谢谢你我该怎么做?我是一个3个月大的婴儿,在这方面这太好笑了。也许我放错地方了。我整晚都在干这个。我把它放在返回真行之前,现在onClick会振动,然后屏幕会稍微变暗,但它不会打开alertdialog。在创建alertdialog之前,请尝试将“alertDialogBuilder.setView(dialogView);”放在上面。我很高兴能帮上忙:)