private void populateSecondForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_password_title))); EditText passwordEditText = createEditText( mContext.getString(R.string.account_create_password_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, PASSWORD_KEY); passwordEditText.setTransformationMethod(new PasswordTransformationMethod()); formLayout.addView(passwordEditText); formLayout.addView(createErrorView(PASSWORD_KEY)); formLayout.addView(createTitle(mContext.getString(R.string.account_create_gender_title))); Spinner spinner = new Spinner(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = 17; spinner.setLayoutParams(params); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( mContext, R.array.sexes_array, android.R.layout.simple_spinner_item); spinner.setAdapter(adapter); spinner.setPrompt(mContext.getString(R.string.account_create_sex_spinner_prompt)); spinner.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { mFormData.put(GENDER_KEY, adapter.getItem(pos).toString()); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); if (mFormData.get(GENDER_KEY) != null) { spinner.setSelection(adapter.getPosition(mFormData.get(GENDER_KEY))); } formLayout.addView(spinner); }
// Adds a reminder to the displayed list of reminders. // Returns true if successfully added reminder, false if no reminders can // be added. static boolean addReminder( Activity activity, View.OnClickListener listener, ArrayList<LinearLayout> items, ArrayList<Integer> values, ArrayList<String> labels, int minutes) { if (items.size() >= MAX_REMINDERS) { return false; } LayoutInflater inflater = activity.getLayoutInflater(); LinearLayout parent = (LinearLayout) activity.findViewById(R.id.reminder_items_container); LinearLayout reminderItem = (LinearLayout) inflater.inflate(R.layout.edit_reminder_item, null); parent.addView(reminderItem); Spinner spinner = (Spinner) reminderItem.findViewById(R.id.reminder_value); Resources res = activity.getResources(); spinner.setPrompt(res.getString(R.string.reminders_title)); int resource = android.R.layout.simple_spinner_item; ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity, resource, labels); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); ImageButton reminderRemoveButton; reminderRemoveButton = (ImageButton) reminderItem.findViewById(R.id.reminder_remove); reminderRemoveButton.setOnClickListener(listener); int index = findMinutesInReminderList(values, minutes); spinner.setSelection(index); items.add(reminderItem); return true; }
private void populateItem() { SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() { public boolean setViewValue(View view, Object data, String textRepresentation) { // We configured the SimpleAdapter to create TextViews (see // the 'to' array, above), so this cast should be safe: TextView textView = (TextView) view; textView.setText(textRepresentation); return true; } }; SimpleAdapter seasonAdapter = new SimpleAdapter( this, seasonList, android.R.layout.simple_spinner_item, new String[] {"seasonName"}, new int[] {android.R.id.text1}); seasonAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); seasonAdapter.setViewBinder(viewBinder); spnSeason.setAdapter(seasonAdapter); spnSeason.setPrompt(getString(R.string.select_season)); SimpleAdapter typeAdapter = new SimpleAdapter( this, typeList, android.R.layout.simple_spinner_item, new String[] {"typeName"}, new int[] {android.R.id.text1}); typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); typeAdapter.setViewBinder(viewBinder); spnType.setAdapter(typeAdapter); spnType.setPrompt(getString(R.string.select_type)); SimpleAdapter statusAdapter = new SimpleAdapter( this, statusList, android.R.layout.simple_spinner_item, new String[] {"statusName"}, new int[] {android.R.id.text1}); statusAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); statusAdapter.setViewBinder(viewBinder); spnStatus.setAdapter(statusAdapter); spnStatus.setPrompt(getString(R.string.select_status)); }
// 选择城市 private void chooseCity() { citySpinner.setPrompt("请选择城市"); final SpinnerAdapter adapter = new SpinnerAdapter(this.context, dtoList.get(provinceSelectedIndex).getChilds()); citySpinner.setAdapter(adapter); try { citySpinner.setSelection(citySelectedIndex); } catch (Exception e) { } citySpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { cityTextView.setText( dtoList.get(provinceSelectedIndex).getChilds().get(position).getName()); selectedAreaId = dtoList.get(provinceSelectedIndex).getChilds().get(position).getId(); adapter.setSelectedIndex(position); citySelectedIndex = position; } @Override public void onNothingSelected(AdapterView<?> parent) {} }); citySpinner.performClick(); }
private void Init() { editTextHost = (EditText) findViewById(R.id.editTextHost); editTextLogin = (EditText) findViewById(R.id.editTextLogin); editTextPassword = (EditText) findViewById(R.id.editTextPassword); buttonSaveSettings = (Button) findViewById(R.id.buttonSaveSettings); buttonCancelSettings = (Button) findViewById(R.id.buttonCancelSettings); editTextHost.setText(config.getServer()); editTextLogin.setText(config.getLogin()); editTextPassword.setText(config.getPassword()); String[] data = {"15 минут", "30 минут", "60 минут"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); Spinner spinner = (Spinner) findViewById(R.id.spinnerUpdate); spinner.setAdapter(adapter); spinner.setPrompt("Частота обновления"); spinner.setSelection(0); spinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {} @Override public void onNothingSelected(AdapterView<?> arg0) {} }); }
// intent投げ先activitiesをspinnerに積む処理 private void buildBrowserSpinner() { // アダプターを設定します ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWdgSpinnerBrowsers = (Spinner) findViewById(R.id.SpinnerBrowsers); mWdgSpinnerBrowsers.setAdapter(adapter); // アイテムを追加します mSuitableApps = getSuitableActivities(); for (int i = 0; i < mSuitableApps.size(); i++) { adapter.add(mSuitableApps.get(i).get("label")); } // スピナーのアイテムが選択された時に呼び出されるコールバックを登録します mWdgSpinnerBrowsers.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // Spinner spinner = (Spinner) parent; // 選択されたアイテムを取得します // String item = (String) spinner.getSelectedItem(); // Log.d(TAG, "spb:sel:" + item); } public void onNothingSelected(AdapterView<?> parent) {} }); // スピナー表示時タイトル mWdgSpinnerBrowsers.setPrompt((CharSequence) getString(R.string.spinnerPrompt_browser)); return; }
// 选择省份 private void chooseProvince() { provinceSpinner.setPrompt("请选择省份"); final SpinnerAdapter adapter = new SpinnerAdapter(this.context, dtoList); provinceSpinner.setAdapter(adapter); adapter.setSelectedIndex(0); provinceSpinner.setSelection(provinceSelectedIndex); provinceSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { provinceTextView.setText(dtoList.get(position).getName()); cityTextView.setText(dtoList.get(position).getChilds().get(0).getName()); adapter.setSelectedIndex(position); provinceSelectedIndex = position; citySelectedIndex = 0; } @Override public void onNothingSelected(AdapterView<?> parent) {} }); provinceSpinner.performClick(); }
void SpinnerSetUp() { sex.setPrompt("جنسیت:"); List<String> list = new ArrayList<String>(); list.add("زن"); list.add("مرد"); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sex.setAdapter(dataAdapter); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shared_pref_example); mResources = getResources(); mTextView = (TextView) findViewById(R.id.textView1); // setting up preferences and preference editor mSharedPreferences = getSharedPreferences(PREFS, 0); mPreferencesEditor = mSharedPreferences.edit(); // set up initial view to show current saved preference (white is default if none saved yet) colorFun(mSharedPreferences.getString(COLOR, mResources.getString(R.string.white))); mTextView.setText( String.format( mResources.getString(R.string.current_preference), mSharedPreferences.getString(COLOR, mResources.getString(R.string.white)))); // set up spinner (dropdown... I don't know why Android calls it a spinner) mSpinner = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.colorList, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mSpinner.setAdapter(adapter); mSpinner.setPrompt(mResources.getString(R.string.pick_one)); mSpinner.setOnItemSelectedListener( new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { colorFun(parent.getItemAtPosition(pos).toString()); } public void onNothingSelected(AdapterView<?> parent) {} }); // set up button mButton = (Button) findViewById(R.id.button1); mButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { // committing the change to preferences mPreferencesEditor.putString(COLOR, colorPref); mPreferencesEditor.commit(); mTextView.setText( String.format(mResources.getString(R.string.current_preference), colorPref)); } }); }
private void populateThirdForm(LinearLayout formLayout) { formLayout.addView(createTitle(mContext.getString(R.string.account_create_city_title))); EditText cityEditText = createEditText( mContext.getString(R.string.account_create_city_hint), InputType.TYPE_CLASS_TEXT, EditorInfo.IME_ACTION_DONE, false, CITY_KEY); if (mFormData.get(CITY_KEY) != null) { cityEditText.setText(mFormData.get(CITY_KEY)); } formLayout.addView(cityEditText); formLayout.addView(createErrorView(CITY_KEY)); formLayout.addView(createTitle(mContext.getString(R.string.account_create_country_title))); Spinner spinner = new Spinner(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); params.bottomMargin = 17; spinner.setLayoutParams(params); final ArrayAdapter<String> adapter = new ArrayAdapter<String>( mContext, android.R.layout.simple_spinner_item, Countries.COUNTRIES); spinner.setAdapter(adapter); spinner.setPrompt(mContext.getString(R.string.account_create_country_spinner_prompt)); spinner.setOnItemSelectedListener( new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { mFormData.put(COUNTRY_KEY, Countries.COUNTRY_CODES[pos]); } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); if (mFormData.get(COUNTRY_KEY) != null) { List<String> array = Arrays.asList(Countries.COUNTRY_CODES); spinner.setSelection(array.indexOf(mFormData.get(COUNTRY_KEY))); } formLayout.addView(spinner); }
@Override protected void internalOnCreate(Bundle savedInstanceState) { bFilter = (ImageButton) findViewById(R.id.bFilter); bFilter.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MassOpActivity.this, BlotterFilterActivity.class); blotterFilter.toIntent(intent); startActivityForResult(intent, FILTER_REQUEST); } }); ImageButton bCheckAll = (ImageButton) findViewById(R.id.bCheckAll); bCheckAll.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { ((BlotterListAdapter) getListAdapter()).checkAll(); } }); ImageButton bUncheckAll = (ImageButton) findViewById(R.id.bUncheckAll); bUncheckAll.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { ((BlotterListAdapter) getListAdapter()).uncheckAll(); } }); final MassOp[] operations = MassOp.values(); final Spinner spOperation = (Spinner) findViewById(R.id.spOperation); Button proceed = (Button) findViewById(R.id.proceed); proceed.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { MassOp op = operations[spOperation.getSelectedItemPosition()]; applyMassOp(op); } }); Intent intent = getIntent(); if (intent != null) { blotterFilter = WhereFilter.fromIntent(intent); applyFilter(); } spOperation.setPrompt(getString(R.string.mass_operations)); spOperation.setAdapter(EnumUtils.createSpinnerAdapter(this, operations)); prepareTransactionActionGrid(); }
private void setSpinnerContent() { ArrayAdapter<String> adapter = null; if (action == MainActivity.ACTION_EIGEN) { String[] eigen = resources.getStringArray(R.array.array_spinner_eigen); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, eigen); spinner.setVisibility(View.VISIBLE); } if (adapter != null) { adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setPrompt("Action"); spinner.setSelection(0); spinner.setOnItemSelectedListener(new ItemSelectedListener()); } }
/** * Helper method to create a spinner for a field and insert it into the View container. This uses, * the String[] to create the list, and selects the value that is passed in from the list (the * features value). Can be used for domains as well as types. */ Spinner createSpinnerViewFromArray(View container, Field field, Object value, String[] values) { TextView fieldAlias = (TextView) container.findViewById(R.id.field_alias_txt); Spinner spinner = (Spinner) container.findViewById(R.id.field_value_spinner); fieldAlias.setText(field.getAlias()); spinner.setPrompt(field.getAlias()); ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this.context, android.R.layout.simple_spinner_item, values); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); // set current selection based on the value passed in spinner.setSelection(spinnerAdapter.getPosition(value.toString())); return spinner; }
// 変換方法一覧spinnerに変換候補を流し込む private void buildConvertSpinner() { // Log.d(TAG, "init:dialog"); // アダプターを設定します ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mWdgSpinnerConverters = (Spinner) findViewById(R.id.SpinnerConverters); mWdgSpinnerConverters.setAdapter(adapter); // アイテムを追加します mConverters = new ArrayList<HashMap<String, String>>(); Cursor c = mDbHelperConverter.fetchAllItems(); startManagingCursor(c); c.moveToFirst(); for (int i = 0; i < c.getCount(); i++) { // 選択項目に追加 adapter.add(c.getString(1)); // 変換項目キャッシュに追加 HashMap<String, String> hm = new HashMap<String, String>(); hm.put("title", c.getString(1)); hm.put("url", c.getString(2)); mConverters.add(hm); Log.d(TAG, "bcs:" + i + ":" + c.getString(1) + "/" + c.getString(2)); c.moveToNext(); } // スピナーのアイテムが選択された時に呼び出されるコールバックを登録します mWdgSpinnerConverters.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Spinner spinner = (Spinner) parent; // 選択されたアイテムを取得します Cursor c = mDbHelperConverter.fetchItemByTitle((String) spinner.getSelectedItem()); startManagingCursor(c); Log.d(TAG, "bcs:ois:sel:" + c.getString(2)); } public void onNothingSelected(AdapterView<?> parent) {} }); // スピナー表示時タイトル mWdgSpinnerConverters.setPrompt((CharSequence) getString(R.string.spinnerPrompt_converter)); // Log.d(TAG, "init:dialog:show:done"); return; }
/** ** validation *** */ private boolean setValidation() { String strName = "" + eTxtName.getText().toString().trim(); String strEmailID = "" + eTxtEmailId.getText().toString().trim(); String strPassword = "" + eTxtPassword.getText().toString().trim(); String strService = "" + spinnerGlobalService.getSelectedItem().toString().trim(); String strNumber = "" + eTxtNumber.getText().toString().trim(); if (strName.length() == 0) { eTxtName.setError("Enter Name"); return false; } if (strEmailID.length() > 0) { if (android.util.Patterns.EMAIL_ADDRESS.matcher(strEmailID).matches()) { } else { eTxtEmailId.setError("Enter valid EmailID"); return false; } } else { eTxtEmailId.setError("Enter EmailID"); return false; } if (strPassword.length() == 0) { eTxtPassword.setError("Enter Password"); return false; } if (strNumber.length() == 0) { eTxtNumber.setError("Please Enter Number"); return false; } else if (strNumber.length() > 10 || strNumber.length() < 10 || !strNumber.matches("\\d{10}")) { eTxtNumber.setError("Please Enter Valid Number"); return false; } if (strService.length() == 0) { spinnerGlobalService.setPrompt("Select the Service"); } return true; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { root = super.onCreateView(inflater, container, savedInstanceState); if (layoutId > 0) { data = new ArrayList(); for (int i = 0; i < AreaFragment.eventList.size(); i++) { data.add(AreaFragment.eventList.get(i).getTitle()); } adapter = new ArrayAdapter<>(getActivity(), R.layout.dropdown_event_list, data); area_autocomplete = (AutoCompleteTextView) root.findViewById(R.id.area_autocomplete); area_autocomplete.requestFocus(); area_autocomplete.setThreshold(1); // will start working from first character area_autocomplete.setAdapter(adapter); // setting the adapter data into the area_autocomplete.setTextColor(Color.DKGRAY); area_autocomplete.setTextSize(16); area_autocomplete.setDropDownVerticalOffset(10); spinner_data = new ArrayList<>(); spinner_data.add("1km"); spinner_data.add("5km"); spinner_data.add("10km"); spinnerAdapter = new ArrayAdapter<>( getActivity(), android.R.layout.simple_spinner_dropdown_item, spinner_data); spinner = (Spinner) root.findViewById(R.id.area_distance_spinner); spinner.setPrompt("거리선택"); spinner.setAdapter(spinnerAdapter); } /* ibwriteSchedule.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EventBus.getDefault().post(new ChangeFragEvent(AreaFragment_Write.class, "이벤트작성")); ibfindSchedule.setVisibility(View.GONE); ibwriteSchedule.setVisibility(View.GONE); ibareaSchedule.setVisibility(View.GONE); } });*/ return root; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = getApplicationContext(); setContentView(R.layout.main); mTextView = (TextView) findViewById(R.id.status); Button registerButton = (Button) findViewById(R.id.register); registerButton.setOnClickListener(mRegisterButtonListener); Spinner accounts = (Spinner) findViewById(R.id.accounts); accounts.setAdapter(getGoogleAccounts(this)); accounts.setPrompt(getString(R.string.accounts)); registerReceiver(mUpdateUIReceiver, new IntentFilter(UPDATE_UI_ACTION)); registerReceiver(mAuthPermissionReceiver, new IntentFilter(AUTH_PERMISSION_ACTION)); // registerReceiver(SmsReceiver, new IntentFilter(SMS_RECEIVED)); updateStatus(); }
public void init() { // Set ActionBar Subtitle ActionBar ab = getActionBar(); ab.setSubtitle(R.string.title_activity_transfer); Intent callerIntent = getIntent(); try { res = new JSONObject(callerIntent.getStringExtra("wizglobal.balRes")); accountList = new JSONArray(callerIntent.getStringExtra("wizglobal.accountList")); Log.d(Config.getDebugTag(), "Account List: " + accountList); selectedAccNo = res.getString("accNo"); selectedAccDesc = res.getString("accDesc"); Log.d(Config.getDebugTag(), "Account Desc: " + selectedAccDesc); balance = res.getString("balance"); // Inputs txtAccNo = (TextView) findViewById(R.id.txtTransAccNo); txtBal = (TextView) findViewById(R.id.txtTransBal); // Set AccNo and Bal txtAccNo.setText(selectedAccDesc); txtBal.setText("KES " + balance); // Initialize Spinner accountNoList = new ArrayList<String>(); accountDescList = new ArrayList<String>(); for (int i = 0; i < accountList.length(); i++) { accountNoList.add(accountList.getJSONObject(i).getString("accountNo")); accountDescList.add(accountList.getJSONObject(i).getString("accountName")); } accountDescList.remove(selectedAccDesc); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>( this, R.layout.wizglobal_spinner_items, accountDescList.toArray(new String[accountDescList.size()])); Spinner spinnerAccountList = (Spinner) findViewById(R.id.accountSpinner); spinnerAccountList.setPrompt(getResources().getString(R.string.spinnerAccountPrompt)); spinnerAccountList.setAdapter(adapter); } catch (Exception e) { e.printStackTrace(); } }
@Test public void testPrompt() { spinner.setPrompt("foo"); assertThat(spinner.getPrompt().toString()).isEqualTo("foo"); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_edit_customer); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); String[] data = {"owner", "rent"}; String status; spinner = (Spinner) findViewById(R.id.spinner); toDayDate = new SimpleDateFormat("dd-MM-yyyy").format(new Date()); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, data); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner = (Spinner) findViewById(R.id.spinner); spinner.setAdapter(adapter); spinner.setPrompt("Title"); spinner.setSelection(0); spinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == 0) { mPosition = 0; } if (position == 1) { mPosition = 1; } } @Override public void onNothingSelected(AdapterView<?> arg0) {} }); mApartmentNumberEditText = (EditText) findViewById(R.id.ApartmentNumberEditText); mFirstNameEditText = (EditText) findViewById(R.id.FirstNameEditText); mLastNameEditText = (EditText) findViewById(R.id.LastNameEditText); mEmailEditText = (EditText) findViewById(R.id.EmailEditText); mPhoneHomeEditText = (EditText) findViewById(R.id.PhoneHomeEditText); mPhoneMobileEditText = (EditText) findViewById(R.id.PhoneMobileEditText); mMonthlyPaymentNumberEditText = (EditText) findViewById(R.id.MonthlyPaymentNumberEditText); mPreviousBalanceEditText = (EditText) findViewById(R.id.PreviousBalanceEditText); mDateEditText = (EditText) findViewById(R.id.DateEditText); Intent intent = getIntent(); mDbOpenHelperCustomer = new DbOpenHelperCustomer(this); int customerId = intent.getIntExtra("ID", -1); if (customerId > -1) { mCustomer = mDbOpenHelperCustomer.getCustomerById(customerId); if (mCustomer != null) { Log.d("MyLog", "som"); edit = true; mApartmentNumberEditText.setText(mCustomer.getApartmentNumber()); mFirstNameEditText.setText(mCustomer.getFirstName()); mLastNameEditText.setText(mCustomer.getLastName()); mEmailEditText.setText(mCustomer.getEmail()); mPhoneHomeEditText.setText(mCustomer.getPhoneHome()); mPhoneMobileEditText.setText(mCustomer.getPhoneMobil()); mMonthlyPaymentNumberEditText.setText(mCustomer.getMonthlyPayment()); mPreviousBalanceEditText.setText(mCustomer.getPreviousBalance()); spinner.setSelection(mCustomer.getCustomerStatus()); mPosition = mCustomer.getCustomerStatus(); mDateEditText.setText(mCustomer.getDate()); } } Button actionButton = (Button) findViewById(R.id.actionButton); if (edit) { actionButton.setText("Update"); apartment = mCustomer.getApartmentNumber(); } else { actionButton.setText("Create"); mDateEditText.setText(toDayDate); } actionButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!edit) { if (!mDbOpenHelperCustomer.idExist(mApartmentNumberEditText.getText().toString())) { Toast.makeText(getApplication(), "Already taken ", Toast.LENGTH_SHORT).show(); return; } } if (edit) { if (!apartment.equals(mApartmentNumberEditText.getText().toString())) { List<Customer> customers = mDbOpenHelperCustomer.getCustomers(); for (Customer customer : customers) { if (customer .getApartmentNumber() .equals(mApartmentNumberEditText.getText().toString())) { Toast.makeText(getApplication(), "Already taken ", Toast.LENGTH_SHORT).show(); return; } } } } if (TextUtils.isEmpty(mApartmentNumberEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(mFirstNameEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(mLastNameEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(mEmailEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(mPhoneHomeEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(mPhoneMobileEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(mMonthlyPaymentNumberEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (TextUtils.isEmpty(mPreviousBalanceEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } // if (TextUtils.isEmpty(mCustomerStatusEditText.getText().toString())) { // Toast.makeText(getApplication(), "All fields must be complete ", // Toast.LENGTH_SHORT).show(); // return; // } if (TextUtils.isEmpty(mDateEditText.getText().toString())) { Toast.makeText(getApplication(), "All fields must be complete ", Toast.LENGTH_SHORT) .show(); return; } if (!edit) { Log.d("MyLog", "new"); mCustomer = new Customer( mApartmentNumberEditText.getText().toString(), mFirstNameEditText.getText().toString(), mLastNameEditText.getText().toString(), mEmailEditText.getText().toString(), mPhoneHomeEditText.getText().toString(), mPhoneMobileEditText.getText().toString(), mMonthlyPaymentNumberEditText.getText().toString(), mPreviousBalanceEditText.getText().toString(), mPosition, mDateEditText.getText().toString()); mDbOpenHelperCustomer.saveCustomer(mCustomer); } else { Log.d("MyLog", "Back"); mCustomer.setApartmentNumber(mApartmentNumberEditText.getText().toString()); mCustomer.setFirstName(mFirstNameEditText.getText().toString()); mCustomer.setLastName(mLastNameEditText.getText().toString()); mCustomer.setEmail(mEmailEditText.getText().toString()); mCustomer.setPhoneHome(mPhoneHomeEditText.getText().toString()); mCustomer.setPhoneMobil(mPhoneMobileEditText.getText().toString()); mCustomer.setMonthlyPayment(mMonthlyPaymentNumberEditText.getText().toString()); mCustomer.setPreviousBalance(mPreviousBalanceEditText.getText().toString()); mCustomer.setCustomerStatus(mPosition); mCustomer.setDate(mDateEditText.getText().toString()); mDbOpenHelperCustomer.updateCustomer(mCustomer); } finish(); } }); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_user_crud, container, false); editTextUserName = (EditText) rootView.findViewById(R.id.editTextUserName); editTextEmail = (EditText) rootView.findViewById(R.id.editTextEmail); editTextLogin = (EditText) rootView.findViewById(R.id.editTextLogin); editTextPassword = (EditText) rootView.findViewById(R.id.editTextPassword); editTextConfirmPassword = (EditText) rootView.findViewById(R.id.editTextConfirmPassword); editTextZipCode = (EditText) rootView.findViewById(R.id.editTextZipCode); editTextAddress = (EditText) rootView.findViewById(R.id.editTextAddress); editTextNumberAddress = (EditText) rootView.findViewById(R.id.editTextNumberAddress); editTextComplement = (EditText) rootView.findViewById(R.id.editTextComplement); editTextNeighborhood = (EditText) rootView.findViewById(R.id.editTextNeighborhood); editTextCity = (EditText) rootView.findViewById(R.id.editTextCity); txtLatitude = (TextView) rootView.findViewById(R.id.txtLatitude); txtLongitude = (TextView) rootView.findViewById(R.id.txtLongitude); radioGroupGender = (RadioGroup) rootView.findViewById(R.id.radioGender); spinnerStates = (Spinner) rootView.findViewById(R.id.spinnerStates); btnSearchZipCode = (Button) rootView.findViewById(R.id.btnSearchZipCode); btnSaveUser = (Button) rootView.findViewById(R.id.btnSaveUser); ArrayAdapter arrayAdapterStates = new ArrayAdapter(getActivity(), R.layout.support_simple_spinner_dropdown_item, states); spinnerStates.setPrompt("Estados"); spinnerStates.setAdapter(arrayAdapterStates); spinnerStates.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position > 0) { String state = (String) spinnerStates.getItemAtPosition(position); spinnerStates.setSelection(states.indexOf(state)); } } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText( getActivity(), "É necessário selecionar uma Categoria", Toast.LENGTH_SHORT) .show(); } }); if (getActivity().getIntent().getSerializableExtra("user") != null) { UserBean userBeanLoad = (UserBean) getActivity().getIntent().getSerializableExtra("user"); editTextUserName.setText(userBeanLoad.getUserName()); editTextEmail.setText(userBeanLoad.getEmail()); editTextLogin.setText(userBeanLoad.getLogin()); editTextPassword.setVisibility(View.INVISIBLE); editTextConfirmPassword.setVisibility(View.INVISIBLE); editTextZipCode.setText(userBeanLoad.getZipCode()); editTextAddress.setText(userBeanLoad.getAddress()); editTextNumberAddress.setText(userBeanLoad.getNumberAddress()); editTextComplement.setText(userBeanLoad.getComplement()); editTextNeighborhood.setText(userBeanLoad.getNeighborhood()); editTextCity.setText(userBeanLoad.getCity()); if (userBeanLoad.getGender().equals(UserBean.Gender.MALE.getSex())) { radioButtonGender = (RadioButton) rootView.findViewById(R.id.radioMale); radioButtonGender.setChecked(true); } else { radioButtonGender = (RadioButton) rootView.findViewById(R.id.radioFemale); radioButtonGender.setChecked(true); } spinnerStates.setSelection(states.indexOf(userBeanLoad.getState())); getActivity() .getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); btnSaveUser.setTag(userBeanLoad); } btnSaveUser.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { progressDialog = ProgressDialog.show(getActivity(), "Processando", "Salvando usuário..."); if (view.getTag() != null) { userBean = (UserBean) view.getTag(); } else { userBean = new UserBean(); } int selectedId = radioGroupGender.getCheckedRadioButtonId(); switch (selectedId) { case R.id.radioFemale: userBean.setGender(UserBean.Gender.FEMALE.getSex()); break; case R.id.radioMale: userBean.setGender(UserBean.Gender.MALE.getSex()); break; } userBean.setUserName(editTextUserName.getText().toString()); userBean.setEmail(editTextEmail.getText().toString()); userBean.setLogin(editTextLogin.getText().toString()); userBean.setPassword(editTextPassword.getText().toString()); userBean.setZipCode(editTextZipCode.getText().toString()); userBean.setAddress(editTextAddress.getText().toString()); userBean.setNumberAddress(editTextNumberAddress.getText().toString()); userBean.setComplement(editTextComplement.getText().toString()); userBean.setNeighborhood(editTextNeighborhood.getText().toString()); userBean.setCity(editTextCity.getText().toString()); userBean.setState(spinnerStates.getSelectedItem().toString()); AsyncTask<Void, Void, JSONObject> task = new AsyncTask<Void, Void, JSONObject>() { @Override protected JSONObject doInBackground(Void... voids) { Http http = new Http(); try { StringBuilder strAddress = new StringBuilder(); strAddress.append(editTextAddress.getText().toString()).append(" "); strAddress.append(editTextNumberAddress.getText().toString()).append(" "); strAddress.append(editTextCity.getText().toString()).append(" "); strAddress.append(spinnerStates.getSelectedItem().toString()); String result = http.doGet( PAGE_MAPS + URLEncoder.encode(strAddress.toString(), "UTF-8") + "&sensor=true"); JSONObject jsonObject = new JSONObject(result); if (jsonObject.getString("status").equals("OK")) { JSONArray jsonArrayResults = jsonObject.getJSONArray("results"); for (int i = 0; i < jsonArrayResults.length(); i++) { JSONObject jsonObjectResults = jsonArrayResults.getJSONObject(i); if (jsonObjectResults.get("geometry") != null) { JSONObject jsonObjectGeometry = jsonObjectResults.getJSONObject("geometry"); return (JSONObject) jsonObjectGeometry.get("location"); } } } } catch (IOException e1) { Log.e(AppHelper.getClassError(UserCrudActivity.class), e1.getMessage()); } catch (JSONException e2) { Log.e(AppHelper.getClassError(UserCrudActivity.class), e2.getMessage()); } return null; } @Override protected void onPostExecute(JSONObject jsonObject) { super.onPostExecute(jsonObject); boolean cepOK = true; if (jsonObject == null || jsonObject.isNull("lng")) { cepOK = false; Toast.makeText(getActivity(), "CEP inexistente.", Toast.LENGTH_SHORT) .show(); } else { try { userBean.setLatitude(jsonObject.get("lat").toString()); userBean.setLongitude(jsonObject.get("lng").toString()); boolean create = userBean.getId() == null ? true : false; UserDB userDB = new UserDB(getActivity()); userBean = userDB.salvar(userBean); if (userBean != null) { Intent it = new Intent(); it.putExtra( "msg", create ? "Usuário salvo com sucesso!" : "Usuário atualizado com sucesso!"); it.putExtra("user", userBean); getActivity().setResult(RESULT_OK, it); getActivity().finish(); } else { Intent it = new Intent(); it.putExtra( "msg", create ? "Falha ao cadastrar o Usuário!" : "Falha ao atualizar Usuário!"); getActivity().setResult(RESULT_CANCELED, it); getActivity().finish(); } } catch (JSONException e3) { Log.e(AppHelper.getClassError(UserCrudActivity.class), e3.getMessage()); } } if (cepOK) { UserDB userDB = new UserDB(getActivity()); userBean = userDB.salvar(userBean); if (userBean != null) { Intent it = new Intent(); it.putExtra( "msg", userBean.getId() == null ? "Usuário salvo com sucesso!" : "Usuário atualizado com sucesso!"); it.putExtra("user", userBean); getActivity().setResult(RESULT_OK, it); getActivity().finish(); } else { Intent it = new Intent(); it.putExtra( "msg", userBean.getId() == null ? "Falha ao cadastrar o Usuário!" : "Falha ao atualizar Usuário!"); getActivity().setResult(RESULT_CANCELED, it); getActivity().finish(); } } } }; if (validateFields(userBean)) { task.execute(); } progressDialog.dismiss(); } }); btnSearchZipCode.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { progressDialog = ProgressDialog.show(getActivity(), "Pesquisando", "Carregando..."); AsyncTask<Void, Void, JSONObject> task = new AsyncTask<Void, Void, JSONObject>() { @Override protected JSONObject doInBackground(Void... params) { Http http = new Http(); try { String result = http.doGet(PAGE_CORREIOS + editTextZipCode.getText().toString()); JSONObject jsonObject = new JSONObject(result); if (!jsonObject.has("message")) { return jsonObject; } } catch (IOException e1) { Log.e(AppHelper.getClassError(UserCrudActivity.class), e1.getMessage()); } catch (JSONException e2) { Log.e(AppHelper.getClassError(UserCrudActivity.class), e2.getMessage()); } return null; } @Override protected void onPostExecute(JSONObject jsonObject) { if (jsonObject == null) { Toast.makeText(getActivity(), "CEP inexistente.", Toast.LENGTH_SHORT) .show(); } else { try { editTextAddress.setText( jsonObject.get("tipoDeLogradouro") + " " + jsonObject.get("logradouro")); editTextNeighborhood.setText(jsonObject.get("bairro").toString()); editTextCity.setText(jsonObject.get("cidade").toString()); spinnerStates.setSelection( states.indexOf(jsonObject.get("estado").toString())); } catch (JSONException e3) { Log.e(AppHelper.getClassError(UserCrudActivity.class), e3.getMessage()); } } progressDialog.dismiss(); } }; task.execute(); } }); return rootView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.library_tell_us); addSecondaryTitle("Tell Us"); mContext = this; mScrollView = (LockingScrollView) findViewById(R.id.scrollView); mSuggestPurchaseButton = (TwoLineActionRow) findViewById(R.id.libraryTellUsSuggestPurchase); mSuggestPurchaseButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { CommonActions.viewURL(mContext, "http://libraries.mit.edu/suggest-purchase"); } }); mFeedbackText = (EditText) findViewById(R.id.feebackText); mFeedbackText.addTextChangedListener(mUpdateSubmitButtonTextWatcher); mStatusSpinner = (Spinner) findViewById(R.id.statusSpinner); mSubmitButton = (Button) findViewById(R.id.submit); mSubmitButton.setEnabled(false); mLoader = (FullScreenLoader) findViewById(R.id.tellUsLoading); mThankYouView = findViewById(R.id.libraryTellUsThankYou); mContentResult = (TwoLineActionRow) findViewById(R.id.librariesThankYouContentActionRow); mGoHomeButton = (TwoLineActionRow) findViewById(R.id.librariesThankYouReturnHome); mGoHomeButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(mContext, getNewModule().getModuleHomeActivity()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); statusArray = getResources().getStringArray(R.array.libraryStatus); String statusTitle = getResources().getString(R.string.libraryStatusTitle); SpinnerAdapter statusAdapter = new SimpleSpinnerAdapter(this, statusTitle, Arrays.asList(statusArray)); mStatusSpinner.setAdapter(statusAdapter); mStatusSpinner.setPrompt(statusTitle); mSubmitButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mSubmitButton.getWindowToken(), 0); int position = mStatusSpinner.getSelectedItemPosition() - 1; String status = null; if (position >= 0) { String[] statusCodeArray = getResources().getStringArray(R.array.libraryStatusCode); status = statusCodeArray[position]; } String feedback = mFeedbackText.getText().toString().trim(); if ("".equals(feedback)) { Toast.makeText(TellUsActivity.this, "Description is required!", Toast.LENGTH_LONG) .show(); return; } mScrollView.setVisibility(View.GONE); mLoader.setVisibility(View.VISIBLE); mLoader.showLoading(); LibraryModel.sendTellUsInfo(TellUsActivity.this, uiHandler, status, feedback); } }); /* showLoader(); VerifyUserCredentials.VerifyUserHasFormAccess(mContext, new VerifyUserCredentialsListener() { @Override public void onUserLoggedIn(UserIdentity user) { showForm(); } }); */ }