Android自定义弹出窗口
Android自定义弹出窗口
search_order.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
builder.setTitle("查询订单"); //设置弹出窗口的标题
View view= LayoutInflater.from(MainActivity.this).inflate(R.layout.search_dialog,null);
final EditText textname=view.findViewById(R.id.search_name); //将输入框对应,以便获取用户输入的文字
builder.setView(view); //把弹出窗口的页面设定为search_dialog.xml设定的页面
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//设定PositiveButton
@Override
public void onClick(DialogInterface dialog, int which) {
String name=textname.getText().toString();
try {
Pair<Float,Float> ans=setSearch_order(name);
new AlertDialog.Builder(MainActivity.this)
.setTitle("查询结果")
.setMessage("总业绩:"+ans.first+"\n"+"已报业绩:"+ans.second+"\n"+"结余业绩:"+(ans.first-ans.second))
.setPositiveButton("确认",null)
.show(); //弹出窗口
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),"无此人数据",Toast.LENGTH_LONG).show();
}
}
});
builder.show();
}
});
CAD加油!欢迎跟我一起讨论学习算法,QQ:1401650042