gpt4 book ai didi

安卓:alertDialog 不工作

转载 作者:行者123 更新时间:2023-11-29 18:18:15 24 4
gpt4 key购买 nike

我正在尝试在单击按钮时添加一个警告对话框,但有些方法不起作用..但我添加的 toast 运行良好。有人可以帮帮我吗?我在创建对象时直接添加了上下文而不是“this”[ new AlertDialog.Builder(context).create(); ] 当我添加这个时,它给我错误“构造函数 AlertDialog.Builder(new View.OnClickListener(){}) 未定义”

       public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
Service service = (Service) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_layout, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.tvChild);
Drawable d = convertView.findViewById(R.id.submit).getBackground();
PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP);
d.setColorFilter(filter);
tv.setText(" " + service.getName());
this.submitButton = (Button)convertView.findViewById(R.id.submit);
this.submitButton.setText("Activate");
this.submitButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(context, "Service Activation Request Send", Toast.LENGTH_LONG).show();
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Alert 1");
alertDialog.setMessage("This is an alert");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
}
});

//this.submitButton.setPadding(20, 0, 0, 0);

// Depending upon the child type, set the imageTextView01
tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
if (service instanceof DataService) {
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.data, 0, 0, 0);
} else if (service instanceof VoiceService) {
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.voice, 0, 0, 0);
} else if (service instanceof SmsService) {
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.sms, 0, 0, 0);
}
return convertView;
}

最佳答案

alertDialog 上调用 show() 方法。

关于安卓:alertDialog 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6982303/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com