alertdialog 自定義view 以及反射

      View  view = (LinearLayout) getLayoutInflater().inflate(R.layout.outlayout,null);
            AlertDialog.Builder builder =new AlertDialog.Builder(DataActivity1.this);
            builder.setTitle("導(dǎo)出數(shù)據(jù)");
            builder.setView(view);


            final EditText 文件名 = (EditText)view.findViewById(R.id.fileName);
            文件名.setText(nowTime);
                    //相當(dāng)于點(diǎn)擊確認(rèn)按鈕
            builder.setPositiveButton("確認(rèn)", 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, "導(dǎo)出成功!",
                                            Toast.LENGTH_SHORT).show();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                    Toast.makeText(DataActivity1.this, "導(dǎo)出失敗!",
                                            Toast.LENGTH_SHORT).show();
                                } catch (WriteException e) {
                                    e.printStackTrace();
                                    Toast.makeText(DataActivity1.this, "導(dǎo)出失敗!",
                                            Toast.LENGTH_SHORT).show();
                                }
                            }

                        }
                    });
    //相當(dāng)于點(diǎn)擊取消按鈕
            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>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容