List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects)
From source file:com.danielme.android.webviewdemo.WebViewDemoActivity.java
@Override protected Dialog onCreateDialog(int id) { Builder builder = new Builder(this); builder.setTitle(getString(R.string.history)); builder.setPositiveButton(getString(R.string.clear), new OnClickListener() { @Override/*from w w w . j a va 2s. c o m*/ public void onClick(DialogInterface dialog, int which) { historyStack.clear(); } }); builder.setNegativeButton(R.string.close, null); dialogArrayAdapter = new ArrayAdapter<Link>(this, R.layout.history, historyStack) { @Override public View getView(int position, View convertView, ViewGroup parent) { //holder pattern LinkHolder holder = null; if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.history, null); holder = new LinkHolder(); holder.setUrl((TextView) convertView.findViewById(R.id.textView1)); holder.setImageView((ImageView) convertView.findViewById(R.id.favicon)); convertView.setTag(holder); } else { holder = (LinkHolder) convertView.getTag(); } Link link = historyStack.get(position); //show title when available if (link.getTitle() != null) { holder.getUrl().setText(link.getTitle()); } else { holder.getUrl().setText(link.getUrl()); } Bitmap favicon = link.getFavicon(); if (favicon == null) { holder.getImageView().setImageDrawable( super.getContext().getResources().getDrawable(R.drawable.favicon_default)); } else { holder.getImageView().setImageBitmap(favicon); } return convertView; } }; builder.setAdapter(dialogArrayAdapter, new OnClickListener() { public void onClick(DialogInterface dialog, int item) { webview.loadUrl(historyStack.get(item).getUrl()); stopButton.setEnabled(true); } }); return builder.create(); }
From source file:com.df.app.carCheck.VehicleInfoLayout.java
/** * ?edit/*from w w w .j a v a2 s.co m*/ */ private void setBrandEdit(final Country country) { // adaptercountrybrand?? final ArrayAdapter<String> adapter; if (country == null) { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1, Helper.getEmptyStringList()); } else { adapter = new ArrayAdapter<String>(rootView.getContext(), android.R.layout.simple_list_item_1, country.getBrandNames()); } final Handler handler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message message) { if (message.what == 0) { brandEdit.setText(""); manufacturerEdit.setText(""); seriesEdit.setText(""); modelEdit.setText(""); } else { Brand brand = country.brands.get(message.what - 1); brandEdit.setText(brand.name); // ??edit if (lastBrandIndex != message.what) { manufacturerEdit.setText(""); seriesEdit.setText(""); modelEdit.setText(""); } setManufacturerEdit(brand); } lastBrandIndex = message.what; return true; } }); // ????manufacturer if (country.getBrandNames().size() == 2) { lastBrandIndex = 1; brandEdit.setText(country.getBrandNames().get(1)); setManufacturerEdit(country.brands.get(0)); return; } // ?brand else { showListDialog(R.string.chooseBrand, adapter, handler); } // brandEdit brandEdit.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { showListDialog(R.string.chooseBrand, adapter, handler); } }); }
From source file:com.mifos.mifosxdroid.online.GroupLoanAccountFragment.java
private void inflateAmortizationSpinner() { showProgress(true);/*w w w . j a v a 2 s . c om*/ App.apiManager.getGroupLoansAccountTemplate(groupId, productId, new Callback<Response>() { @Override public void success(final Response result, Response response) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return; Log.d(LOG_TAG, "Loan Account Loaded"); final List<AmortizationType> amortizationType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> amortizationTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try { reader = new BufferedReader(new InputStreamReader(result.getBody().in())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("amortizationTypeOptions")) { JSONArray amortizationTypes = obj.getJSONArray("amortizationTypeOptions"); for (int i = 0; i < amortizationTypes.length(); i++) { JSONObject amortizationTypeObject = amortizationTypes.getJSONObject(i); AmortizationType amortization = new AmortizationType(); amortization.setId(amortizationTypeObject.optInt("id")); amortization.setValue(amortizationTypeObject.optString("value")); amortizationType.add(amortization); amortizationTypeNames.add(amortizationTypeObject.optString("value")); amortizationTypeIdHashMap.put(amortization.getValue(), amortization.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> amortizationTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, amortizationTypeNames); amortizationTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_amortization.setAdapter(amortizationTypeAdapter); sp_amortization.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { amortizationTypeId = amortizationTypeIdHashMap.get(amortizationTypeNames.get(i)); Log.d("ammortization" + amortizationTypeNames.get(i), String.valueOf(amortizationTypeId)); if (amortizationTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT) .show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); showProgress(false); } @Override public void failure(RetrofitError retrofitError) { Log.d(LOG_TAG, retrofitError.getLocalizedMessage()); showProgress(false); } }); }
From source file:com.openerp.addons.note.EditNoteFragment.java
public void setCurrentNoteStages(Context context) { stages = new HashMap<String, String>(); ArrayList<String> stagelist = new ArrayList<String>(); db = new NoteDBHelper(context); NoteDBHelper.NoteStages stagesobj = db.new NoteStages(context); HashMap<String, Object> data = stagesobj.search(stagesobj); int total = Integer.parseInt(data.get("total").toString()); if (total > 0) { @SuppressWarnings("unchecked") List<HashMap<String, Object>> rows = (List<HashMap<String, Object>>) data.get("records"); for (HashMap<String, Object> row_data : rows) { String row_id = row_data.get("id").toString(); String name = row_data.get("name").toString(); stages.put(name, row_id);//from ww w . ja v a2 s.c o m stagelist.add(name); } } noteStages = (Spinner) rootview.findViewById(R.id.spinner_editNote_Stage); stageAdapter = new ArrayAdapter<String>(scope.context(), android.R.layout.simple_spinner_dropdown_item, stagelist); noteStages.setAdapter(stageAdapter); int spinnerPosition = stageAdapter.getPosition(handleStages(stageid).toString()); // setting the Orginal Value noteStages.setSelection(spinnerPosition); }
From source file:com.housekeeper.ar.healthhousekeeper.RegisterActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*/* w ww . j av a 2s . c o m*/ if (savedInstanceState != null) { String zcpsStr = savedInstanceState.getString("zcps"); zcpsET.setText(zcpsStr); } */ SysApplication.getInstance().addActivity(this); setContentView(R.layout.activity_register); toastCommom = ToastCommom.createToastConfig(); MyActivityManager.pushOneActivity(RegisterActivity.this); myApp = (MyApp) getApplication(); http = myApp.getHttp(); backBtn = (Button) findViewById(R.id.back_btn); backBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); //APP? Log.i(TAG, "filename oncreate "); String fileName = myApp.getJoStartPath(); Log.i(TAG, "fileName:" + fileName); if (fileName != null) { try { readFileCache = saveCache.read(fileName); joReadFileCache = new JSONObject(readFileCache); String result = joReadFileCache.getString("result"); String resultMessage = joReadFileCache.getString("resultMessage"); //?value JSONObject joValue = joReadFileCache.getJSONObject("value"); //?provinces jaProvinces = joValue.getJSONArray("provinces"); joProvinces = new JSONObject[jaProvinces.length()]; nameProvinces = new String[jaProvinces.length()]; //nameProvinces[0] = "-?-"; for (int i = 0; i < jaProvinces.length(); i++) { joProvinces[i] = jaProvinces.getJSONObject(i); nameProvinces[i] = joProvinces[i].getString("name"); Log.v(TAG, "nameProvinces:" + nameProvinces[i]); } jaPros = joValue.getJSONArray("jobTitles"); joPros = new JSONObject[jaPros.length()]; namePros = new String[jaPros.length()]; idJobTitles = new int[namePros.length]; for (int i = 0; i < jaPros.length(); i++) { joPros[i] = jaPros.getJSONObject(i); namePros[i] = joPros[i].getString("name"); idJobTitles[i] = joPros[i].getInt("id"); Log.v(TAG, "namePros:" + namePros[i]); Log.v(TAG, "idJobTitles:" + idJobTitles[i]); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { nameProvinces = new String[] { "" }; nameCities = new String[] { "" }; nameHospitals = new String[] { "" }; nameDepartments = new String[] { "" }; namePros = new String[] { "" }; } // prePageBtn = (Button)findViewById(R.id.pre_btn); firstPageLayout = (RelativeLayout) findViewById(R.id.first_layout); // nextPageBtn = (Button)findViewById(R.id.next_btn); // secondPageLayout = (RelativeLayout)findViewById(R.id.second_layout); yanzhengmaLayout = (LinearLayout) findViewById(R.id.yanzhengma_layout); yanzhengmaRegBtn = (Button) findViewById(R.id.yanzhengma_regbtn); titleTextView = (TextView) findViewById(R.id.title); yanzhengmaPsdEditText = (EditText) findViewById(R.id.password_et); yanzhengmaZhangHuEditText = (EditText) findViewById(R.id.zhanghu_et); workIdEditText = (EditText) findViewById(R.id.work_id_et); usernameET = (TextView) findViewById(R.id.username_et); psdET = (TextView) findViewById(R.id.psd_et); psdaET = (EditText) findViewById(R.id.psd_again_et); nameET = (EditText) findViewById(R.id.name_et); idET = (EditText) findViewById(R.id.id_et); // yszET = (EditText)findViewById(R.id.zyys_et); // zczET = (EditText)findViewById(R.id.yszc_et); // zcpsET = (EditText)findViewById(R.id.zcps_et); // skillET = (EditText)findViewById(R.id.zs_et); // detailET = (EditText)findViewById(R.id.xxxx_et); telET = (EditText) findViewById(R.id.tel_et); mailET = (EditText) findViewById(R.id.mail_et); photo = (ImageView) findViewById(R.id.photo_image); // meetplacET = (EditText)findViewById(R.id.address_et); regBtn = (Button) findViewById(R.id.regbtn); photoBtn = (Button) findViewById(R.id.photoBtn); // zcpsBtn = (Button)findViewById(R.id.zcps_btn); // zyysBtn = (Button)findViewById(R.id.zyys_btn); // yszcBtn = (Button)findViewById(R.id.yszc_btn); signBtn = (Button) findViewById(R.id.sign_btn); //birthday birthdayStr = yearStr + "-" + monthStr + "-" + dayStr; year = (Spinner) findViewById(R.id.yearspinner); month = (Spinner) findViewById(R.id.monthspinner); day = (Spinner) findViewById(R.id.dayspinner); //sex sex = (Spinner) findViewById(R.id.sex_spinner); //province-city-hospital sheng = (Spinner) findViewById(R.id.sheng_spinner); shi = (Spinner) findViewById(R.id.shi_spinner); yy = (Spinner) findViewById(R.id.yy_spinner); //? // pro = (Spinner)findViewById(R.id.pro_spinner); //- // ks = (Spinner)findViewById(R.id.ks_spinner); //ksfl = (Spinner)findViewById(R.id.ksfl_spinner); // departmentTypeTv = (TextView)findViewById(R.id.ksfl_tv); final List<String> yearList = getYearData(); final List<String> monthList = getMonthData(); final List<String> dayList = getDayData(); yanzhengmaLayout.setVisibility(View.VISIBLE); firstPageLayout.setVisibility(View.GONE); yanzhengmaRegBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { yanzhengmaLayout.setVisibility(View.GONE); firstPageLayout.setVisibility(View.VISIBLE); titleTextView.setText(" "); usernameET.setText(yanzhengmaZhangHuEditText.getText().toString()); psdET.setText(yanzhengmaPsdEditText.getText().toString()); psdaET.setText(yanzhengmaPsdEditText.getText().toString()); telET.setText(yanzhengmaZhangHuEditText.getText().toString()); } }); // final String yearArray[] = new String[yearList.size()]; // if(yearList != null){ // for(int i = 0 ;i<yearList.size();i++){ // yearArray[i] = yearList.get(i); // } // } // // ArrayAdapter?? // ArrayAdapter<String> yearAdapter = new ArrayAdapter<String> // (RegisterActivity.this, android.R.layout.simple_spinner_item,getYearData()); // ArrayAdapter<String> monthAdapter = new ArrayAdapter<String> // (RegisterActivity.this, android.R.layout.simple_spinner_item,getMonthData()); // ArrayAdapter<String> dayAdapter = new ArrayAdapter<String> // (RegisterActivity.this, android.R.layout.simple_spinner_item,getDayData()); // // final List<String> sexList = getSexData(); // ArrayAdapter<String> sexAdapter = new ArrayAdapter<String> // (RegisterActivity.this, android.R.layout.simple_spinner_item,getSexData()); // ArrayAdapter?? ArrayAdapter<String> yearAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item, yearList) { @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.spinner_item_layout, null); TextView label = (TextView) view.findViewById(R.id.spinner_item_label); label.setText(yearList.get(position)); return view; //return super.getDropDownView(position, convertView, parent); } }; ArrayAdapter<String> monthAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item, getMonthData()) { @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.spinner_item_layout, null); TextView label = (TextView) view.findViewById(R.id.spinner_item_label); label.setText(monthList.get(position)); return view; //return super.getDropDownView(position, convertView, parent); } }; ArrayAdapter<String> dayAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item, getDayData()) { @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.spinner_item_layout, null); TextView label = (TextView) view.findViewById(R.id.spinner_item_label); label.setText(dayList.get(position)); return view; //return super.getDropDownView(position, convertView, parent); } }; final List<String> sexList = getSexData(); ArrayAdapter<String> sexAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item, getSexData()) { @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.spinner_item_layout, null); TextView label = (TextView) view.findViewById(R.id.spinner_item_label); label.setText(sexList.get(position)); return view; //return super.getDropDownView(position, convertView, parent); } }; //? yearAdapter.setDropDownViewResource(R.layout.spinner_item_layout); //? monthAdapter.setDropDownViewResource(R.layout.spinner_item_layout); //? dayAdapter.setDropDownViewResource(R.layout.spinner_item_layout); //? sexAdapter.setDropDownViewResource(R.layout.spinner_item_layout); year.setAdapter(yearAdapter); month.setAdapter(monthAdapter); day.setAdapter(dayAdapter); sex.setAdapter(sexAdapter); year.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { Log.i(TAG, "year touch "); closeSoftKeyboard(); return false; } }); month.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { Log.i(TAG, "year touch "); closeSoftKeyboard(); return false; } }); day.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { Log.i(TAG, "year touch "); closeSoftKeyboard(); return false; } }); sex.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { Log.i(TAG, "year touch "); closeSoftKeyboard(); return false; } }); getShared(); setSpinner(); regBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if (usernameET.getText().toString().equals("")) { // Toast.makeText(RegisterActivity.this, "??", // Toast.LENGTH_LONG).show(); toastCommom.ToastShow(RegisterActivity.this, (ViewGroup) findViewById(R.id.toast_layout_root), "??"); return; } if (psdET.getText().toString().equals("")) { // Toast.makeText(RegisterActivity.this, "?", // Toast.LENGTH_LONG).show(); toastCommom.ToastShow(RegisterActivity.this, (ViewGroup) findViewById(R.id.toast_layout_root), "?"); return; } if (psdaET.getText().toString().equals("")) { // Toast.makeText(RegisterActivity.this, "?", // Toast.LENGTH_LONG).show(); toastCommom.ToastShow(RegisterActivity.this, (ViewGroup) findViewById(R.id.toast_layout_root), "?"); return; } if (!psdaET.getText().toString().equals(psdET.getText().toString())) { Log.v(TAG, "??"); // Toast.makeText(RegisterActivity.this, "??", // Toast.LENGTH_LONG).show(); toastCommom.ToastShow(RegisterActivity.this, (ViewGroup) findViewById(R.id.toast_layout_root), "??"); return; } if (nameET.getText().toString().equals("")) { // Toast.makeText(RegisterActivity.this, "??", // Toast.LENGTH_LONG).show(); toastCommom.ToastShow(RegisterActivity.this, (ViewGroup) findViewById(R.id.toast_layout_root), "??"); return; } pDialog = new ProgressDialog(RegisterActivity.this); pDialog.setTitle(""); pDialog.setMessage("?......"); pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); pDialog.show(); new RegisterThread().run(); } }); photoBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub picKind = 0; Intent intent = new Intent(RegisterActivity.this, SelectPictureActivity.class); intent.putExtra("from", "register"); startActivityForResult(intent, REQUEST_PICK); //RegisterActivity.this.finish(); } }); signBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub picKind = 1; Intent intent = new Intent(RegisterActivity.this, SelectPictureActivity.class); intent.putExtra("from", "register"); startActivityForResult(intent, REQUEST_PICK); } }); }
From source file:com.appolis.receiving.AcReceiveOptionMove.java
/** * function to initial layout/*from w w w. j a v a 2 s.c o m*/ */ private void initLayout() { linBack = (ImageView) findViewById(R.id.imgHome); linBack.setVisibility(View.GONE); linScan = (ImageView) findViewById(R.id.img_main_menu_scan_barcode); linScan.setOnClickListener(this); linScan.setVisibility(View.GONE); tvHeader = (TextView) findViewById(R.id.tvHeader); tvHeader.setText( languagePrefs.getPreferencesString(GlobalParams.RID_LBL_MOVE_KEY, GlobalParams.RID_LBL_MOVE_VALUE)); tvMoveFunctionTitle = (TextView) findViewById(R.id.textView_move); tvMoveFunctionTitle.setText(languagePrefs.getPreferencesString(GlobalParams.MV_MSG_SELECTORSCAN_KEY, GlobalParams.MV_MSG_SELECTORSCAN_VALUE)); tvTitleTransfer = (TextView) findViewById(R.id.tvTitleTransfer); tvTitleTransfer.setText(languagePrefs.getPreferencesString(GlobalParams.TRANSFER, GlobalParams.TRANSFER) + GlobalParams.VERTICAL_TWO_DOT); tvTitleMaxQty = (TextView) findViewById(R.id.tvTitleMaxQty); tvTitleMaxQty.setText( languagePrefs.getPreferencesString(GlobalParams.MV_LBL_MAXQTY, GlobalParams.DMG_LBL_MAXQTY_VALUE) + ": "); tvUOM = (TextView) findViewById(R.id.tvUOM); tvUOM.setText( languagePrefs.getPreferencesString(GlobalParams.MV_LBL_UOM, GlobalParams.UNIT_OF_MEASURE_VALUE) + GlobalParams.VERTICAL_TWO_DOT); tvLot = (TextView) findViewById(R.id.tvLot); tvLot.setText(languagePrefs.getPreferencesString(GlobalParams.REST_GRD_LOT_KEY, GlobalParams.LOT) + GlobalParams.VERTICAL_TWO_DOT); tvFrom = (TextView) findViewById(R.id.tvFrom); tvFrom.setText(languagePrefs.getPreferencesString(GlobalParams.MV_LBL_FROM, GlobalParams.FROM) + GlobalParams.VERTICAL_TWO_DOT); tvQtyView = (TextView) findViewById(R.id.tvQtyView); tvQtyView.setText(languagePrefs.getPreferencesString(GlobalParams.RID_GRD_QTY_KEY, GlobalParams.QTY)); tvTo = (TextView) findViewById(R.id.tvTo); tvTo.setText(languagePrefs.getPreferencesString(GlobalParams.MV_LBL_TO, GlobalParams.TO) + GlobalParams.VERTICAL_TWO_DOT); tvmaxQty = (TextView) findViewById(R.id.tvmaxQty); tvItemDescription = (TextView) findViewById(R.id.tvItemDescription); tvTransfer = (TextView) findViewById(R.id.tvTransfer); spnMoveUOM = (Spinner) findViewById(R.id.spn_Move_UOM); edtLotValue = (EditText) findViewById(R.id.edtLotValue); edtMoveFrom = (EditText) findViewById(R.id.edt_move_from); edtMoveQty = (EditText) findViewById(R.id.et_move_qty); edtMoveQty.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (null != s && s.length() == 1 && s.toString().equalsIgnoreCase(".")) { edtMoveQty.setText(""); s = ""; } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); edtMoveQty.setFilters( new InputFilter[] { new DecimalDigitsInputFilter(enPurchaseOrderItemInfo.get_significantDigits()), new InputFilter.LengthFilter(14) }); edtMoveTo = (EditText) findViewById(R.id.et_move_to); btMoveOk = (Button) findViewById(R.id.btnOK); btMoveOk.setText(languagePrefs.getPreferencesString(GlobalParams.OK, GlobalParams.OK)); btMoveOk.setOnClickListener(this); btMoveOk.setEnabled(true); btMoveCancel = (Button) findViewById(R.id.btnCancel); btMoveCancel.setText(languagePrefs.getPreferencesString(GlobalParams.CANCEL, GlobalParams.CANCEL)); btMoveCancel.setOnClickListener(this); edtMoveTo.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { linScan.setVisibility(View.VISIBLE); scanFlag = GlobalParams.FLAG_ACTIVE; } else { linScan.setVisibility(View.GONE); scanFlag = GlobalParams.FLAG_INACTIVE; } } }); if (null != enPurchaseOrderItemInfo) { tvTransfer.setText(enPurchaseOrderItemInfo.get_itemNumber()); tvItemDescription.setText(enPurchaseOrderItemInfo.get_itemDesc()); } if (null != enPurchaseOrderInfo) { if (StringUtils.isNotBlank(enPurchaseOrderInfo.get_receivingBinNumber())) { edtMoveFrom.setText(enPurchaseOrderInfo.get_receivingBinNumber()); } else { edtMoveFrom.setText(""); } edtMoveFrom.setEnabled(false); } if (null != listReceiptInfos) { if (listReceiptInfos.size() == 1) { Log.e("Appolis", "single record was selected from the previous screen"); EnPurchaseOrderReceiptInfo recipt = listReceiptInfos.get(0); maxQty = recipt.get_quantityReceived(); tvmaxQty.setText(BuManagement.formatDecimal(recipt.get_quantityReceived()).trim()); edtLotValue.setText(recipt.get_lotNumber()); edtLotValue.setEnabled(false); edtMoveQty.setText(BuManagement.formatDecimal(recipt.get_quantityReceived()).trim()); edtMoveQty.setEnabled(true); spnMoveUOM.setEnabled(true); edtMoveTo.requestFocus(); GetDataAsyncTask getDataAsyncTask = new GetDataAsyncTask(this, enPurchaseOrderItemInfo.get_itemNumber()); getDataAsyncTask.execute(); } else { Logger.error("Appolis: multiple records have been selected on the previous screen"); String strlot = ""; int index = 0; for (EnPurchaseOrderReceiptInfo item : listReceiptInfos) { maxQty += item.get_quantityReceived(); if (StringUtils.isNotBlank(item.get_lotNumber())) { if (index == 0) { strlot = strlot + item.get_lotNumber(); } else { strlot = strlot + ", " + item.get_lotNumber(); } index++; } } tvmaxQty.setText(BuManagement.formatDecimal(maxQty).trim()); edtMoveTo.requestFocus(); edtLotValue.setText(strlot); edtLotValue.setEnabled(false); edtMoveQty.setText(BuManagement.formatDecimal(maxQty).trim()); edtMoveQty.setEnabled(false); spnMoveUOM.setEnabled(false); uom = enPurchaseOrderItemInfo.get_uomDesc(); ArrayList<String> listUom = new ArrayList<String>(); listUom.add(uom); ArrayAdapter<String> uomAdapter = new ArrayAdapter<String>(this, R.layout.custom_spinner_item, listUom); spnMoveUOM.setAdapter(uomAdapter); } } }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
private void inflateInterestCalculationPeriodSpinner(ResponseBody result) { final List<InterestCalculationPeriodType> interestCalculationPeriodType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> interestCalculationPeriodTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try {/*from w w w .j av a2 s. c o m*/ reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("interestCalculationPeriodTypeOptions")) { JSONArray interestCalculationPeriodTypes = obj.getJSONArray("interestCalculationPeriodTypeOptions"); for (int i = 0; i < interestCalculationPeriodTypes.length(); i++) { JSONObject interestCalculationPeriodTypeObject = interestCalculationPeriodTypes .getJSONObject(i); InterestCalculationPeriodType interestCalculationPeriod = new InterestCalculationPeriodType(); interestCalculationPeriod.setId(interestCalculationPeriodTypeObject.optInt("id")); interestCalculationPeriod.setValue(interestCalculationPeriodTypeObject.optString("value")); interestCalculationPeriodType.add(interestCalculationPeriod); interestCalculationPeriodTypeNames.add(interestCalculationPeriodTypeObject.optString("value")); interestCalculationPeriodTypeIdHashMap.put(interestCalculationPeriod.getValue(), interestCalculationPeriod.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> interestCalculationPeriodTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, interestCalculationPeriodTypeNames); interestCalculationPeriodTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_interestcalculationperiod.setAdapter(interestCalculationPeriodTypeAdapter); sp_interestcalculationperiod.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { interestCalculationPeriodTypeId = interestCalculationPeriodTypeIdHashMap .get(interestCalculationPeriodTypeNames.get(i)); Log.d("interestCalculation " + interestCalculationPeriodTypeNames.get(i), String.valueOf(interestCalculationPeriodTypeId)); if (interestCalculationPeriodTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_interestCalculationPeriod), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.ichi2.anki.ModelBrowser.java
private void addNewNoteTypeDialog() { String add = getResources().getString(R.string.model_browser_add_add); String clone = getResources().getString(R.string.model_browser_add_clone); // AnkiDroid doesn't have stdmodels class or model name localization, this could be much cleaner if implemented final String basicName = "Basic"; final String addForwardReverseName = "Basic (and reversed card)"; final String addForwardOptionalReverseName = "Basic (optional reversed card)"; final String addClozeModelName = "Cloze"; //Populates arrayadapters listing the mModels (includes prefixes/suffixes) mNewModelLabels = new ArrayList<>(); //Used to fetch model names mNewModelNames = new ArrayList<>(); mNewModelLabels.add(String.format(add, basicName)); mNewModelLabels.add(String.format(add, addForwardReverseName)); mNewModelLabels.add(String.format(add, addForwardOptionalReverseName)); mNewModelLabels.add(String.format(add, addClozeModelName)); mNewModelNames.add(basicName);//from w w w . ja v a 2 s . c o m mNewModelNames.add(addForwardReverseName); mNewModelNames.add(addForwardOptionalReverseName); mNewModelNames.add(addClozeModelName); final int numStdModels = mNewModelLabels.size(); if (mModels != null) { for (JSONObject model : mModels) { try { mNewModelLabels.add(String.format(clone, model.getString("name"))); mNewModelNames.add(model.getString("name")); } catch (JSONException e) { throw new RuntimeException(e); } } } final Spinner addSelectionSpinner = new Spinner(this); ArrayAdapter<String> mNewModelAdapter = new ArrayAdapter<>(this, R.layout.dropdown_deck_item, mNewModelLabels); addSelectionSpinner.setAdapter(mNewModelAdapter); new MaterialDialog.Builder(this).title(R.string.model_browser_add).positiveText(R.string.dialog_ok) .customView(addSelectionSpinner, true).callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { mModelNameInput = new EditText(ModelBrowser.this); mModelNameInput.setSingleLine(); //Temporary workaround - Lack of stdmodels class if (addSelectionSpinner.getSelectedItemPosition() < numStdModels) { mModelNameInput.setText(randomizeName( mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition()))); } else { mModelNameInput .setText(mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition()) + " " + getResources().getString(R.string.model_clone_suffix)); } mModelNameInput.setSelection(mModelNameInput.getText().length()); //Create textbox to name new model new MaterialDialog.Builder(ModelBrowser.this).title(R.string.model_browser_add) .positiveText(R.string.dialog_ok).customView(mModelNameInput, true) .callback(new MaterialDialog.ButtonCallback() { @Override public void onPositive(MaterialDialog dialog) { String modelName = mModelNameInput.getText().toString(); addNewNoteType(modelName, addSelectionSpinner.getSelectedItemPosition()); } }).negativeText(R.string.dialog_cancel).show(); } }).negativeText(R.string.dialog_cancel).show(); }
From source file:edu.cens.loci.ui.widget.GenericEditorView.java
/** * Prepare this editor using the given {@link DataKind} for defining * structure and {@link ValuesDelta} describing the content to edit. *///from w w w.j a v a 2s .c om public void setValues(DataKind kind, ValuesDelta entry, EntityDelta state, boolean readOnly, ViewIdGenerator vig) { mKind = kind; mEntry = entry; mState = state; mReadOnly = readOnly; mViewIdGenerator = vig; setId(vig.getId(state, kind, entry, ViewIdGenerator.NO_VIEW_INDEX)); final boolean enabled = !readOnly; //Log.d(TAG, "setValues: kind=" + mKind.mimeType); if (!entry.isVisible()) { // Hide ourselves entirely if deleted setVisibility(View.GONE); return; } else { setVisibility(View.VISIBLE); } // Display label selector if multiple types available final boolean hasTypes = EntityModifier.hasEditTypes(kind); mLabel.setVisibility(hasTypes ? View.VISIBLE : View.GONE); mLabel.setEnabled(enabled); if (hasTypes) { mType = EntityModifier.getCurrentType(entry, kind); rebuildLabel(); } // Build out set of fields mFields.removeAllViews(); boolean hidePossible = false; int n = 0; if (mKind.mimeType.equals(WifiFingerprint.CONTENT_ITEM_TYPE)) { //Log.d(TAG, "setValues: Wifi"); for (EditField field : kind.fieldList) { Button fieldView = (Button) mInflater.inflate(RES_WIFI_FIELD, mFields, false); mWifiFieldButtonId = vig.getId(state, kind, entry, n++); fieldView.setId(mWifiFieldButtonId); final String column = field.column; final String value = entry.getAsString(column); fieldView.setText("Fingerprint on " + MyDateUtils.getAbrv_MMM_d_h_m(new Long(value))); final String extra1column = field.extra1; final String extra1value = entry.getAsString(extra1column); try { mWifiFingerprint = new LociWifiFingerprint(extra1value); mWifiFingerprintTimeStamp = MyDateUtils.getDateFormatLong(new Long(value)); } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "LociWifiFingerprint parsing failed"); e.printStackTrace(); } // Hide field when empty and optional value final boolean couldHide = (field.optional); final boolean willHide = (mHideOptional && couldHide); fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE); fieldView.setEnabled(enabled); hidePossible = hidePossible || couldHide; fieldView.setOnClickListener(this); mFields.addView(fieldView); } } else if (mKind.mimeType.equals(Keyword.CONTENT_ITEM_TYPE)) { //Log.d(TAG, "setValues: Keywords"); for (EditField field : kind.fieldList) { AutoCompleteTextView fieldView = (AutoCompleteTextView) mInflater.inflate(RES_AUTOCOMPLETE_FIELD, mFields, false); fieldView.setId(vig.getId(state, kind, entry, n++)); if (field.titleRes > 0) { fieldView.setHint(field.titleRes); } int inputType = field.inputType; fieldView.setInputType(inputType); fieldView.setMinLines(field.minLines); // Read current value from state final String column = field.column; final String value = entry.getAsString(column); fieldView.setText(value); // Prepare listener for writing changes fieldView.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { // Trigger event for newly changed value onFieldChanged(column, s.toString()); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); // Hide field when empty and optional value final boolean couldHide = (field.optional); final boolean willHide = (mHideOptional && couldHide); fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE); fieldView.setEnabled(enabled); hidePossible = hidePossible || couldHide; String[] usedKeywords = getResources().getStringArray(R.array.keyword_default); LociDbUtils myDb = new LociDbUtils(getContext()); ArrayList<String> suggestedKeywords = myDb.getSavedKeywords(); HashSet<String> suggestedKeywordsSet = new HashSet<String>(); for (String keyword : suggestedKeywords) { suggestedKeywordsSet.add(keyword); } //Log.d(TAG, "size of usedKeywords : " + usedKeywords.length); //Log.d(TAG, "size of suggestedKeywords : " + suggestedKeywords.size()); for (String usedKeyword : usedKeywords) { if (!suggestedKeywordsSet.contains(usedKeyword)) suggestedKeywords.add(usedKeyword); } //Log.d(TAG, "size of suggestedKeywords : " + suggestedKeywords.size()); Collections.sort(suggestedKeywords); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getContext(), R.layout.item_suggestion_list, suggestedKeywords); fieldView.setAdapter(adapter); fieldView.setThreshold(0); mFields.addView(fieldView); } } else { //Log.d(TAG, "General Types..."); for (EditField field : kind.fieldList) { // Inflate field from definition EditText fieldView = (EditText) mInflater.inflate(RES_FIELD, mFields, false); fieldView.setId(vig.getId(state, kind, entry, n++)); if (field.titleRes > 0) { fieldView.setHint(field.titleRes); } int inputType = field.inputType; fieldView.setInputType(inputType); if (inputType == InputType.TYPE_CLASS_PHONE) { fieldView.addTextChangedListener(new PhoneNumberFormattingTextWatcher()); } fieldView.setMinLines(field.minLines); // Read current value from state final String column = field.column; final String value = entry.getAsString(column); fieldView.setText(value); //Log.d(TAG, "setValues: column=" + column); //Log.d(TAG, "setValues: value=" + value); // Prepare listener for writing changes fieldView.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { // Trigger event for newly changed value onFieldChanged(column, s.toString()); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); // Hide field when empty and optional value final boolean couldHide = (field.optional); final boolean willHide = (mHideOptional && couldHide); fieldView.setVisibility(willHide ? View.GONE : View.VISIBLE); fieldView.setEnabled(enabled); hidePossible = hidePossible || couldHide; mFields.addView(fieldView); } } // When hiding fields, place expandable if (hidePossible) { mMore.setVisibility(mHideOptional ? View.VISIBLE : View.GONE); mLess.setVisibility(mHideOptional ? View.GONE : View.VISIBLE); } else { mMore.setVisibility(View.GONE); mLess.setVisibility(View.GONE); } mMore.setEnabled(enabled); mLess.setEnabled(enabled); }
From source file:edu.umich.oasis.testapp.TestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); kvsValueField = (EditText) findViewById(R.id.kvs_value); shouldTaintBox = (CheckBox) findViewById(R.id.is_tainted); rootLayout = (RelativeLayout) findViewById(R.id.root_layout); sandboxCount = (Spinner) findViewById(R.id.sandbox_count); sandboxCountType = (Spinner) findViewById(R.id.sandbox_count_type); perfPassCount = (EditText) findViewById(R.id.perf_pass_count); taintPerfBox = (CheckBox) findViewById(R.id.perf_taint); // Set up adapter for sandbox count spinner CharSequence[] countList = new CharSequence[OASISConstants.NUM_SANDBOXES + 1]; for (int i = 0; i <= OASISConstants.NUM_SANDBOXES; i++) { countList[i] = getResources().getQuantityString(R.plurals.sandbox_plurals, i, i); }/*from w w w .j a v a 2 s . co m*/ ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, countList); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sandboxCount.setAdapter(adapter); sandboxCount.setSelection(OASISConstants.NUM_SANDBOXES); adapter = ArrayAdapter.createFromResource(this, R.array.sandbox_count_labels, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sandboxCountType.setAdapter(adapter); setButtonsEnabled(false); connectToOASIS(null); }