//自定义弹出框对话框
LayoutInflater factory = LayoutInflater.from(QuZheng2Activity.this);
// 把布局文件中的控件定义在View中
final View textEntryView = factory.inflate(R.layout.item_tianjiatiaomu, null);
new AlertDialog.Builder(QuZheng2Activity.this)
// 对话框的标题
.setTitle("自定义添加条目")
// 设定显示的View
.setView(textEntryView)
// 对话框中的“完成”按钮的点击事件
.setPositiveButton("完成", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
EditText etname1 = (EditText) textEntryView.findViewById(R.id.etname1);
EditText etname2 = (EditText) textEntryView.findViewById(R.id.etname2);
EditText etname3 = (EditText) textEntryView.findViewById(R.id.etname3);
EditText etname4 = (EditText) textEntryView.findViewById(R.id.etname4);
EditText etname5 = (EditText) textEntryView.findViewById(R.id.etname5);
String checkCode1 = etname1.getText().toString().trim();
String checkCode2 = etname2.getText().toString().trim();
String checkCode3 = etname3.getText().toString().trim();
String checkCode4 = etname4.getText().toString().trim();
String checkCode5 = etname5.getText().toString().trim();
if (TextUtils.isEmpty(etname1.getText().toString())||TextUtils.isEmpty(etname2.getText().toString())||TextUtils.isEmpty(etname3.getText().toString())||TextUtils.isEmpty(etname4.getText().toString())||TextUtils.isEmpty(etname5.getText().toString())){
Toast.makeText(QuZheng2Activity.this,"不能为空",Toast.LENGTH_SHORT).show();
}else {
compensationItem.setName(checkCode1);
compensationItem.setSpec(checkCode2);
compensationItem.setUnit(checkCode4);
compensationItem.setQuantity(Integer.valueOf(checkCode3));
compensationItem.setPrice(Integer.valueOf(checkCode5));
select_recyclerViewData.add(compensationItem);
Toast.makeText(QuZheng2Activity.this,compensationItem.getName()+""+compensationItem.getUnit()+""+compensationItem.getSpec()+""+compensationItem.getPrice(),Toast.LENGTH_SHORT).show();
lcqdAdapter.notifyDataSetChanged();
}
}
})
// 对话框的“退出”单击事件
.setNegativeButton("退出", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//不做操作,关闭对话框
}
})
// 设置dialog是否为模态,false表示模态,true表示非模态
.setCancelable(false)
// 对话框的创建、显示
.create().show();
/从接口中获取列表数据添加到列表中
http://image.so.com/j?q=beijing&sn=0&pn=50
AlertDialog.Builder builder = new AlertDialog.Builder(QuZheng2Activity.this,android.R.style.Theme_Holo_Light_Dialog);
//builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("请选择证件类型");
// 指定下拉列表的显示数据
ArrayList<String> stringArrayList = new ArrayList<String>();
for (int i=0; i<zhengjianlist.size(); i++) {
String json_data = zhengjianlist.get(i).getName();
stringArrayList.add(json_data); //add to arraylist
}
final String [] stringArray = stringArrayList.toArray(new String[stringArrayList.size()]);
// 设置一个下拉的列表选择项
builder.setItems(stringArray, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
String s = stringArray[which];
party_card.setText(s);
}
});
builder.show();
///死数据弹出框列表
AlertDialog.Builder builder = new AlertDialog.Builder(QuZheng2Activity.this,android.R.style.Theme_Holo_Light_Dialog);
//builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("请选择方向");
// 指定下拉列表的显示数据
final String[] shuzu = new String[]{"宁波-上海","上海-宁波"};
// 设置一个下拉的列表选择项
builder.setItems(shuzu, new DialogInterface.OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
String s = shuzu[which];
fangxiang.setText(s);
}
});
builder.show();