View view = (LinearLayout) getLayoutInflater().inflate(R.layout.outlayout,null);
AlertDialog.Builder builder =new AlertDialog.Builder(DataActivity1.this);
builder.setTitle("导出数据");
builder.setView(view);
final EditText 文件名 = (EditText)view.findViewById(R.id.fileName);
文件名.setText(nowTime);
//相当于点击确认按钮
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String fileName = 文件名.getText() + "";
if (fileName.length() < 1){
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, false);
} catch (Exception e) {
e.printStackTrace();
}
}else{
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, true);
} catch (Exception e) {
e.printStackTrace();
}
ExcelOperTest ex = new ExcelOperTest();
try {
ex.DataWrite2Excel(DataActivity1.dataList,fileName + ".xls");
Toast.makeText(DataActivity1.this, "导出成功!",
Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(DataActivity1.this, "导出失败!",
Toast.LENGTH_SHORT).show();
} catch (WriteException e) {
e.printStackTrace();
Toast.makeText(DataActivity1.this, "导出失败!",
Toast.LENGTH_SHORT).show();
}
}
}
});
//相当于点击取消按钮
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.create();
builder.show();
//布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/outPut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="6"
android:padding="5dp"
android:text="11111111111111111"
tools:text="11111111111"
android:id="@+id/fileName" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="0dp"
android:text=".xls"
android:id="@+id/样方代码textView"
android:textColor="@android:color/black" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>