Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android警报对话框视图到父视图_Android_Android Alertdialog - Fatal编程技术网

Android警报对话框视图到父视图

Android警报对话框视图到父视图,android,android-alertdialog,Android,Android Alertdialog,我有一个警报对话框生成器,其中显示编辑文本框和其他一些 将其转换为普通视图(父视图) 添加代码: 公共同步的void showPopUp(最终字符串picturePath){ ScrollView ScrollView=新的ScrollView(此); AlertDialog.Builder alert=新建AlertDialog.Builder(此); LinearLayout alertLayout=新的LinearLayout(此); InputFilter[]InputFilter=新的

我有一个警报对话框生成器,其中显示编辑文本框和其他一些 将其转换为普通视图(父视图)

添加代码:

公共同步的void showPopUp(最终字符串picturePath){

ScrollView ScrollView=新的ScrollView(此);
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
LinearLayout alertLayout=新的LinearLayout(此);
InputFilter[]InputFilter=新的InputFilter[1];
inputFilter[0]=新的inputFilter.LengthFilter(50);
alertLayout.setOrientation(1);//1表示垂直方向
最终编辑文本名称输入=新编辑文本(本);
nameInput.setHint(“收据名称”);
nameInput.setFilters(inputFilter);
;
nameInput.setSingleLine(真);
最终文本视图日期文本=新文本视图(此);
dateText.setText(“接收日期”);
最终编辑文本amtInput=新编辑文本(本);
amtInput.setHint(“收款金额”);
amtInput.setSingleLine(真);
digitKeyListener digitKeyListener=新的digitKeyListener(false,true);
amtInput.setKeyListener(digitKeyListener);
InputFilter[]amtInputFilter=新的InputFilter[2];
amtInputFilter[0]=新的InputFilter(){
公共CharSequence筛选器(CharSequence源、int开始、int结束、,
跨越目的地、内部数据起点、内部数据起点){
如果(结束>开始){
字符串destTxt=dest.toString();
String resultingTxt=destTxt.substring(0,dstart)
+源.子序列(开始,结束)
+destTxt.substring(dend);
如果(!resultingTxt
[1-9[1-9[1-9[1-9[1-9[1-9[1-9]{{{0,2{{3{{3{{{3})(\,,,,,,,,,,,,\\\\\\{3{3{3})的比赛(((((^,,,,,,,,,[3{{{3{3})3})*)*)*)*((\\\\\\\\\\.[0 0{00 0 0 0 0,0,0,2 0,2}))???????????????????????????????????????)))))))));;;;;;;;;;;;;;;;(((\\\\\\\....(1-9)0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0 0,0 0,0,0 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0 0,0 0 0 0,0 0))??????????????????[[1-1-1-1-9[1-9[1-9[1-9[1-9[1-9[1-9[1-9[1[1-9[1[1[1-9[1[1-9]]]除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了除了上述上述上述上述上述上述上述上述两两两,0,0,0,0,0,0,0 2})?|(\\.\\d{1,2}))\\)$")) {
返回“”;
}
}
返回null;
}
};
amtInputFilter[1]=新的InputFilter.LengthFilter(13);
设置过滤器(amtInputFilter);
setOnEditorActionListener(新的OnEditorActionListener(){
公共布尔onEditorAction(TextView v,int actionId,
关键事件(事件){
if(event!=null&&event.getAction()!=KeyEvent.ACTION\u向下)
返回false;
如果(actionId==EditorInfo.IME\u ACTION\u NEXT
||事件==null
||event.getKeyCode()==KeyEvent.KEYCODE\u ENTER){
InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT\u METHOD\u SERVICE);imm.hideSoftInputFromWindow(amtInput.getWindowToken(),0);
}
返回false;
}
});
最终日期选择器DatePicker=新日期选择器(此);
datePicker.clearFocus();
datePicker.bringToFront();
alertLayout.addView(名称输入);
alertLayout.addView(amtInput);
alertLayout.addView(日期文本);
alertLayout.addView(日期选择器);
scrollView.addView(alertLayout);
alert.setView(滚动视图);
alert.setTitle(“输入费用明细”);
alert.setPositiveButton(“保存”,新建DialogInterface.OnClickListener()){
public void onClick(对话框接口对话框,int whichButton){
rcptName=nameInput.getText().toString();
rcptAmt=amtInput.getText().toString();
int spinnerDate=datePicker.getDayOfMonth();
int spinnerMonth=datePicker.getMonth()+1;
if(喷丝头月份<10和喷丝头日期<10){
rcptDate=(datePicker.getYear())+“0”+(spinnerMonth)
+“0”+喷丝头;
}否则如果(喷丝头月份<10){
rcptDate=(datePicker.getYear())+“0”+(spinnerMonth)
+''+喷丝头;
}否则如果(喷丝头日期<10){
rcptDate=(datePicker.getYear())+“”+(spinnerMonth)
+“0”+喷丝头;
}否则{
rcptDate=(datePicker.getYear())+“”+(spinnerMonth)
+''+喷丝头;
}
保存首选项(“RNAME”,rcptName);
SavePreferences(“RAMOUNT”,rcptAmt);
保存首选项(“RDATE”,rcptDate);
SharedReferences SharedReferences=GetSharedReferences(
“LoginPref”,0);
字符串username=SharedReferences.getString(“用户名”,null);
字符串guid=SharedReferences.getString(“guid”,null);
字符串密码=SharedReferences.getString(“密码”,null);
String rcptName=SharedReferences.getString(“RNAME”,null);
字符串rcptAmount=SharedReferences
.getString(“RAMOUNT”,null);
字符串rcptDate=SharedReferences.getString(“RDATE”,null);
String uploadLocation=SharedReferences.getString(“LOGINURL”,
无效);
if(rcptAmount.isEmpty()| | rcptName==null
||rcptName.isEmpty()| | rcptName.trim().isEmpty()){
显示弹出窗口(图片路径);
}否则{
如果(isInternetOn()){
新建UploadTask().execute(图片路径、用户名、guid、,
rcptName、RCPTMount、rcptDate、上载位置、,
密码);
}否则{
完成();
}
}
}
});
alert.setOnKeyListener(新的DialogInterface.OnKeyListener(){
公共布尔onKey(对话框接口对话框,int-keyCode,
关键事件(事件){
//白名单允许的键-仅允许导航键
if(keyCode==KeyEvent.keyCode\u搜索){
返回true;
}
返回false;
    ScrollView scrollView = new ScrollView(this);
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    LinearLayout alertLayout = new LinearLayout(this);

    InputFilter[] inputFilter = new InputFilter[1];
    inputFilter[0] = new InputFilter.LengthFilter(50);

    alertLayout.setOrientation(1); // 1 is for vertical orientation
    final EditText nameInput = new EditText(this);
    nameInput.setHint("Receipt Name");
    nameInput.setFilters(inputFilter);
    ;
    nameInput.setSingleLine(true);

    final TextView dateText = new TextView(this);
    dateText.setText("Receipt Date");

    final EditText amtInput = new EditText(this);
    amtInput.setHint("Receipt Amount");
    amtInput.setSingleLine(true);

    DigitsKeyListener digitKeyListener = new DigitsKeyListener(false, true);
    amtInput.setKeyListener(digitKeyListener);

    InputFilter[] amtInputFilter = new InputFilter[2];
    amtInputFilter[0] = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end,
                Spanned dest, int dstart, int dend) {
            if (end > start) {
                String destTxt = dest.toString();
                String resultingTxt = destTxt.substring(0, dstart)
                        + source.subSequence(start, end)
                        + destTxt.substring(dend);
                if (!resultingTxt
                        .matches("^\\$?\\-?([1-9]{1}[0-9]{0,2}(\\,\\d{3})*(\\.\\d{0,2})?|[1-9]{1}\\d{0,}(\\.\\d{0,2})?|0(\\.\\d{0,2})?|(\\.\\d{1,2}))$|^\\-?\\$?([1-9]{1}\\d{0,2}(\\,\\d{3})*(\\.\\d{0,2})?|[1-9]{1}\\d{0,}(\\.\\d{0,2})?|0(\\.\\d{0,2})?|(\\.\\d{1,2}))$|^\\(\\$?([1-9]{1}\\d{0,2}(\\,\\d{3})*(\\.\\d{0,2})?|[1-9]{1}\\d{0,}(\\.\\d{0,2})?|0(\\.\\d{0,2})?|(\\.\\d{1,2}))\\)$")) {
                    return "";
                }
            }
            return null;
        }
    };
    amtInputFilter[1] = new InputFilter.LengthFilter(13);
    amtInput.setFilters(amtInputFilter);

    amtInput.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView v, int actionId,
                KeyEvent event) {
            if (event != null && event.getAction() != KeyEvent.ACTION_DOWN)
                return false;
            if (actionId == EditorInfo.IME_ACTION_NEXT
                || event == null
                || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {                  


                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(amtInput.getWindowToken(), 0);


            }
            return false;
        }



});

final DatePicker datePicker = new DatePicker(this);

    datePicker.clearFocus();
    datePicker.bringToFront();



    alertLayout.addView(nameInput);
    alertLayout.addView(amtInput);
    alertLayout.addView(dateText);
    alertLayout.addView(datePicker);
    scrollView.addView(alertLayout);
    alert.setView(scrollView);

    alert.setTitle("Enter Expense Detail");

    alert.setPositiveButton("SAVE", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {

            rcptName = nameInput.getText().toString();
            rcptAmt = amtInput.getText().toString();

            int spinnerDate = datePicker.getDayOfMonth();
            int spinnerMonth = datePicker.getMonth() + 1;

            if (spinnerMonth < 10 && spinnerDate < 10) {
                rcptDate = (datePicker.getYear()) + "0" + (spinnerMonth)
                        + "0" + spinnerDate;
            } else if (spinnerMonth < 10) {
                rcptDate = (datePicker.getYear()) + "0" + (spinnerMonth)
                        + "" + spinnerDate;
            } else if (spinnerDate < 10) {
                rcptDate = (datePicker.getYear()) + "" + (spinnerMonth)
                        + "0" + spinnerDate;
            } else {
                rcptDate = (datePicker.getYear()) + "" + (spinnerMonth)
                        + "" + spinnerDate;
            }

            SavePreferences("RNAME", rcptName);
            SavePreferences("RAMOUNT", rcptAmt);
            SavePreferences("RDATE", rcptDate);

            SharedPreferences sharedPreferences = getSharedPreferences(
                    "LoginPref", 0);
            String username = sharedPreferences.getString("USERNAME", null);
            String guid = sharedPreferences.getString("GUID", null);
            String password = sharedPreferences.getString("PASSWORD", null);
            String rcptName = sharedPreferences.getString("RNAME", null);
            String rcptAmount = sharedPreferences
                    .getString("RAMOUNT", null);
            String rcptDate = sharedPreferences.getString("RDATE", null);
            String uploadLocation = sharedPreferences.getString("LOGINURL",
                    null);


            if (rcptAmount.isEmpty() || rcptName == null
                    || rcptName.isEmpty() || rcptName.trim().isEmpty()) {
                showPopUp(picturePath);

            } else {


                if (isInternetOn()) {

                    new UploadTask().execute(picturePath, username, guid,
                            rcptName, rcptAmount, rcptDate, uploadLocation,
                            password);

                } else {


                    finish();
                }

            }
        }
    });

    alert.setOnKeyListener(new DialogInterface.OnKeyListener() {

        public boolean onKey(DialogInterface dialog, int keyCode,
                KeyEvent event) {
            // whitelist allowed keys - allow navigation keys only
            if (keyCode == KeyEvent.KEYCODE_SEARCH) {
                return true;
            }
            return false;

        }
    });

    alert.setNegativeButton("CANCEL",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    finish();
                    startActivity(getIntent());
                }
            });

    alert.setCancelable(false);

    alert.show();

}