InputType.TYPE_NUMBER_FLAG_DECIMAL无效

这篇博客主要介绍了如何在Android中设置输入框为浮点数类型,并确保其在用户界面显示时自动弹出键盘。通过使用`InputType.TYPE_NUMBER_FLAG_DECIMAL|InputType.TYPE_CLASS_NUMBER`组合,可以实现浮点数输入。同时,为了确保键盘显示,使用了Handler延迟执行弹窗操作,并设置了焦点和选择全部文本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

--设置输入浮点数数字。
editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);



--有弹窗必须先弹窗,然后再设置。
  new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodControl.showInputMethod(ct,editText);
                editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER);
                editText.selectAll();
                editText.setFocusable(true);
            }
        },100);


	public static void showInputMethod(Context context) {
		//自动弹出键盘
		InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
		inputManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
		//强制隐藏Android输入法窗口
		// inputManager.hideSoftInputFromWindow(edit.getWindowToken(),0);
	}

	/**
	 * 显示键盘
	 * @param context
	 * @param view
	 */
	public static void showInputMethod(Context context, View view) {
		InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
		im.showSoftInput(view, 0);
	}

import os class trans_table: def __init__(self): # 0 1 2 3 4 5 6 self.target_v = ['Suite name', 'Test name', 'Test number', 'Bin_s_num', 'Bin_h_num', 'Bin_type', 'Bin_overon'] self.qaandft = ['Lsl_typ', 'Usl_typ', 'Lsl', 'Usl', 'Units'] self.file_head_file_name = '' self.file_head = ['#LimitTable,,,,,,,,,,,,,,,,,,,,,\n', '#Block,LimitTableBlock,'+self.file_head_file_name+',,,,,,,,,,,,,,,,,,,\n', 'SetNames,,,,,,,Default,Default,,,,,,,,,,,,,\n', '#Title,FlowName,TestInstance,TestName,TestNumber,LowCompsign,HighCompsign,LowLimit,HighLimit,' 'Scale,Units,Format,SPassBin,SFailBin,HPassBin,HFailBin,Result,ActionPass,ActionFail,Assume,' 'Sites,Comment\n'] self.line_head = 'LimitItem,' self.line_tail = ',,,,,\n' self.compsign = {'GE': '>=', 'GT': '>', 'LE': '<=', 'LT': '<', 'NA': 'NA', '': ''} self.overon = {'no': 'FailStop', 'yes': 'Fail', '': '', 'good': 'Pass'} self.flow = {} self.ltm_flag = False self.xml_head = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' self.ltf_head = '<limittablefile version="1.1">\n <limitpairs>\n <limitpair>Default</limitpair>\n </limitpairs>\n <limittable>\n' self.ltf_tail = ' </limittable>\n</limittablefile>' self.ltm_head = '<limittablemaster version="1.1">\n' self.ltm_tail = '</limittablemaster>' self.ltf_list = [] def reset(self): self.flow = {} self.ltf_list = [] def set_newfile_head(self, stmp): self.file_head_file_name = stmp.strip('.csv')+'.ltf' self.file_head = ['#LimitTable,,,,,,,,,,,,,,,,,,,,,\n', '#Block,LimitTableBlock,' + self.file_head_file_name + ',,,,,,,,,,,,,,,,,,,\n', 'SetNames,,,,,,,Default,Default,,,,,,,,,,,,,\n', '#Title,FlowName,TestInstance,TestName,TestNumber,LowCompsign,HighCompsign,LowLimit,HighLimit,' 'Scale,Units,Format,SPassBin,SFailBin,HPassBin,HFailBin,Result,ActionPass,ActionFail,Assume,' 'Sites,Comment\n'] def read_file(self, fpath, inpath, outpath): fpath = fpath.replace('\\', '/') inpath = inpath.replace('\\', '/') outpath = outpath.replace('\\', '/') l_index = 0 head = [] mode = [] data_main = [] data_qa = [] data_ft = [] with open(fpath) as f: for line in f.readlines(): l_index += 1 l = line.strip().split(',') for ii in range(len(l)): l[ii] = l[ii].strip('\"') if l_index == 1: head = l if head[:3] != ['Suite name', 'Test name', 'Test number']: print('Error file:' + fpath) return else: print('Reading file:' + fpath) elif l_index == 2: mode = l elif l_index > 2: tmp_data_main = [''] * len(self.target_v) tmp_data_qa = [''] * len(self.qaandft) tmp_data_ft = [''] * len(self.qaandft) for il in range(len(l)): if l[il] == '': continue if head[il] in self.target_v: tmp_data_main[self.target_v.index(head[il])] = l[il] elif head[il] in self.qaandft: # phoneix sys only allow 6 number after . if '.' in l[il]: tmpli = l[il].split('.') if len(tmpli) == 2 and tmpli[1].isdigit() and len(tmpli[1]) > 6: if int(tmpli[1][6]) > 4: tmptail = str(int(tmpli[1][:6])+1) while len(tmptail) < 6: tmptail = '0'+tmptail l[il] = tmpli[0] + '.' + tmptail else: l[il] = tmpli[0] + '.' + tmpli[1][:6] if 'FT' in mode[il]: tmp_data_ft[self.qaandft.index(head[il])] = l[il] elif 'QA' in mode[il]: tmp_data_qa[self.qaandft.index(head[il])] = l[il] data_main.append(tmp_data_main) data_ft.append(tmp_data_ft) data_qa.append(tmp_data_qa) if self.ltm_flag: self.xml_write(data_main, data_ft, data_qa, fpath, inpath, outpath) else: self.file_write(data_main, data_ft, data_qa, fpath, inpath, outpath) def xml_write(self, main, ft, qa, fpath, inpath, outpath): print(fpath, inpath) tmnp_fpath = fpath.split('/') tmpqa = outpath f = open(tmpqa +'/'+ tmnp_fpath[-1][:-3]+'ltf', 'w') print('Writing file:' + tmpqa + tmnp_fpath[-1][:-3]+'ltf') f.writelines(self.xml_head) f.writelines(self.ltf_head) for tmpi in range(len(main)): s_tmp = self.xml_convert(main[tmpi], ft[tmpi]) if s_tmp: f.writelines(s_tmp) f.writelines(self.ltf_tail) f.close() self.ltf_list.append(tmnp_fpath[-1][:-3]+'ltf') def xml_convert(self, main, detail): tmp = self.convert(main, detail) tmp_l = tmp.split(',') re = '' if tmp_l[2]: re = ' <row comment=\"\" flowname=\"'+tmp_l[1]+'\" testinstance=\"'+tmp_l[2]+'\" testname=\"'+tmp_l[3]+'\" testnumber=\"'+tmp_l[4]+'">\n'+' <action/>\n <bin hfailbin=\"'+tmp_l[15]+'\" hpassbin=\"'+tmp_l[14]+'\" result=\"'+tmp_l[16]+'\" sfailbin=\"'+tmp_l[13]+'\" spassbin=\"'+tmp_l[12]+'\"/>\n <limit highcompsign=\"'+tmp_l[6]+'\" lowcompsign=\"'+tmp_l[5]+'\" units=\"'+tmp_l[10]+'\">\n <pair highlimit=\"'+tmp_l[8]+'\" lowlimit=\"'+tmp_l[7]+'\" name=\"Default\"/>\n </limit>\n </row>\n' return re def write_ltm(self, outpath): f = open(outpath+'/tmp.ltm', 'w') f.writelines(self.xml_head) f.writelines(self.ltm_head) for l in self.ltf_list: f.write(' <limittablefile path=\"'+l+'\"/>\n') f.writelines(self.ltm_tail) f.close() def file_write(self, main, ft, qa, fpath, inpath, outpath): tmnp_fpath = fpath.split(inpath, 1)[1].split('/') tmpqa = outpath+'/QA'+'/'.join(tmnp_fpath[:-1]) tmpft = outpath+'/FT'+'/'.join(tmnp_fpath[:-1]) if not os.path.exists(tmpqa): os.makedirs(tmpqa) if not os.path.exists(tmpft): os.makedirs(tmpft) qaf = open(tmpqa+'/QA_cc_'+tmnp_fpath[-1], 'w') print('Writing file:'+tmpqa+'/FT_cc_'+tmnp_fpath[-1]) print('Writing file:'+tmpft+'/FT_cc_'+tmnp_fpath[-1]) self.set_newfile_head(tmnp_fpath[-1]) qaf.writelines(self.file_head) ftf = open(tmpft+'/FT_cc_'+tmnp_fpath[-1], 'w') ftf.writelines(self.file_head) for tmpi in range(len(main)): qaf.write(self.convert(main[tmpi], qa[tmpi])) ftf.write(self.convert(main[tmpi], ft[tmpi])) qaf.close() ftf.close() def convert(self, main, detail): # 0 1 2 3 4 5 6 # main = ['Suite name', 'Test name', 'Test number', 'Bin_s_num', 'Bin_h_num', 'Bin_type', 'Bin_overon'] if not main[0]: return ',,,,,,,,,,,,,,,,,,,,\n' re = main[0]+','+main[1]+','+main[2]+',' re += self.compsign[detail[0]]+','+self.compsign[detail[1]]+','+detail[2]+','+detail[3]+',1,'+detail[4]+',,' if main[5] == 'bad': re += ','+main[3]+',,'+main[4]+','+self.overon[main[6]] else: print(main) re += main[3] + ',,' + main[4] + ',,' + self.overon[main[5]] tmp_head = self.line_head if self.flow.get(main[0]): tmp_head += self.flow[main[0]]+',' else: tmp_head += 'mainflow,' return tmp_head+re+self.line_tail def read_flow(self, flow_fname): flow_fname = flow_fname.replace('\\', '/') if not flow_fname: return tmp = flow_fname.split('/')[-1] flow_path = flow_fname[:len(flow_fname)-len(tmp)] flow_name = tmp.split('.')[0] with open(flow_fname) as f_name: for line in f_name.readlines(): l = line.split() if l: if l[0] == '<row': opcode = line.split('opcode=\"')[-1].split('\"')[0] testname = line.split('operand=\"')[-1].split('\"')[0] if opcode == 'Test': if self.flow.get(testname) and self.flow[testname] != flow_name: self.flow[testname] += '|'+flow_name else: self.flow[testname] = flow_name elif opcode == 'Call': self.read_flow(flow_path+testname) def execute(self, inpath, mfh, outpath, flow_f, ltm_flag = False): # if not mfh: # file_list = find_file(inpath) # else: # file_list = an_find_file(mfh) self.reset() self.ltm_flag = ltm_flag for fff in flow_f: self.read_flow(fff) if not mfh: file_list = find_file(inpath) for files in file_list: if 'FT_cc_' not in files and 'QA_cc_' not in files: self.read_file(files, inpath, outpath) else: file_list = an_find_file(mfh) for files in file_list: if 'FT_cc_' not in files and 'QA_cc_' not in files: self.read_file(files, inpath, outpath) if self.ltm_flag: self.write_ltm(outpath) def find_file(path): l = [] for ospath, dirs, files in os.walk(path): for file in files: if os.path.splitext(file)[1] == '.csv': l.append(os.path.join(ospath, file)) for dir in dirs: l += find_file(os.path.join(ospath, dir)) return l def an_find_file(mfh): re = [] mfh = mfh.replace('\\', '/') tmp = mfh.split('/') path = '/'.join(tmp[:-1]) f_mfh = tmp[-1] with open(mfh) as f: for line in f.readlines(): l = line.split('#')[0].split() if len(l) >2 and l[0] == 'testerfile' and l[1] == ':': re.append(path+'/'+l[2]) return re '''if __name__ == '__main__': path = './' table_f = find_file(path) tt = trans_table() print(table_f) tt.execute(table_f, path, path) input('press any key to end!')''' 优化上述代码的格式,命名,调用
最新发布
08-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值