private void showUserHashDialog() { String userHash = NavigineApp.Settings.getString("user_hash", ""); LayoutInflater inflater = getLayoutInflater(); View view = inflater.inflate(R.layout.user_hash_dialog, null); _userEdit = (EditText) view.findViewById(R.id.user_hash_edit); _userEdit.setText(userHash); _userEdit.setTypeface(Typeface.MONOSPACE); // _userEdit.addTextChangedListener(new TextWatcher() // { // public void afterTextChanged(Editable s) { } // public void beforeTextChanged(CharSequence s, int start, int count, int after) { } // public void onTextChanged(CharSequence s, int start, int before, int count) // { // String text = _userEdit.getText().toString(); // int length = _userEdit.getText().length(); // // if (text.endsWith("-")) // return; // // if (count <= before) // return; // // if (length == 4 || length == 9 || length == 14) // { // _userEdit.setText((text + "-")); // _userEdit.setSelection(length + 1); // } // } // }); AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mContext); alertBuilder.setView(view); alertBuilder.setTitle("Enter user ID"); alertBuilder.setNegativeButton( getString(R.string.cancel_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int id) {} }); alertBuilder.setPositiveButton( getString(R.string.ok_button), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dlg, int id) { String userHash = _userEdit.getText().toString(); SharedPreferences.Editor editor = NavigineApp.Settings.edit(); editor.putString("user_hash", userHash); editor.commit(); NavigineApp.applySettings(); refreshMapList(); } }); AlertDialog dialog = alertBuilder.create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); }
private void setUpNoteFromDatabase(Intent intent) { long id = intent.getLongExtra(EXTRA_NOTE_ID, 1); Log.d(TAG, "Got ID " + id + " from intent extra"); note = noteProvider.getNote(id); Log.d(TAG, "Retrieved the following Note from the database: " + note.toString()); if (note.getTitle().equals(PLACEHOLDER_TEXT_FOR_DATABASE)) { note.setTitle(""); } if (note.getBody().equals(PLACEHOLDER_TEXT_FOR_DATABASE)) { note.setBody(""); } titleEditText.setText(note.getTitle()); bodyEditText.setText(note.getBody()); noteExistsInDatabase = true; }
public void mOnClick(View v) { switch (v.getId()) { case R.id.test: String rootdir = Environment.getRootDirectory().getAbsolutePath(); String datadir = Environment.getDataDirectory().getAbsolutePath(); String cachedir = Environment.getDownloadCacheDirectory().getAbsolutePath(); mEdit.setText( String.format( "ext = %s\nroot=%s\ndata=%s\ncache=%s", mSdPath, rootdir, datadir, cachedir)); break; case R.id.save: File dir = new File(mSdPath + "/dir"); dir.mkdir(); File file = new File(mSdPath + "/dir/file.txt"); try { FileOutputStream fos = new FileOutputStream(file); String str = "This file exists in SDcard"; fos.write(str.getBytes()); fos.close(); mEdit.setText("write success"); } catch (FileNotFoundException e) { mEdit.setText("File Not Found." + e.getMessage()); } catch (SecurityException e) { mEdit.setText("Security Exception"); } catch (Exception e) { mEdit.setText(e.getMessage()); } break; case R.id.load: try { FileInputStream fis = new FileInputStream(mSdPath + "/dir/file.txt"); byte[] data = new byte[fis.available()]; while (fis.read(data) != -1) {; } fis.close(); mEdit.setText(new String(data)); } catch (FileNotFoundException e) { mEdit.setText("File Not Found"); } catch (Exception e) {; } break; } }
@Override public void onExprItemClick(String exprInfo, boolean isDel) { SpannableString ss; int textSize = (int) editText.getTextSize(); if (isDel) { HashMap<String, Integer> mExprFilenameIdData = XWExpressionManager.getInstance().getmExprInfoIdValuesCN(getActivity()); ss = XWExpressionUtil.generateSpanComment( getActivity().getApplicationContext(), XWExpressionUtil.deleteOneWord(editText.getText().toString(), mExprFilenameIdData), textSize); } else { String content = editText.getText() + exprInfo; ss = XWExpressionUtil.generateSpanComment( getActivity().getApplicationContext(), content, textSize); } editText.setText(ss); editText.setSelection(ss.length()); }
@Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent); if ((actionId == EditorInfo.IME_ACTION_DONE) || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) { Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER"); String input = textView.getText().toString().trim(); if (input.length() > 0) { String result = ""; try { result += calculator.calculate(input); } catch (Exception e) { result = "no result (" + e.getMessage() + ")"; } if (listAdapter.getCount() > 0) { listAdapter.add(""); } listAdapter.add(input + " ="); if (input.indexOf("@") > -1) { listAdapter.add(calculator.getEquation() + " ="); } listAdapter.add(result); listAdapter.notifyDataSetChanged(); inputView.endBatchEdit(); inputView.setText(""); hideKeyboard(); } } return false; }
@Override public void onClick(View v) { TextView txtManageLabel, txtBrowseLabel, txtRefreshLabel, txtSearchLabel; txtManageLabel = (TextView) findViewById(R.id.txt_manage_label); txtBrowseLabel = (TextView) findViewById(R.id.txt_browse_label); txtRefreshLabel = (TextView) findViewById(R.id.txt_refresh_label); txtSearchLabel = (TextView) findViewById(R.id.txt_search_label); txtSearch.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { new AsyncTask<String, Void, ArrayList<RssItem>>() { @Override protected ArrayList<RssItem> doInBackground(String... params) { return dbQuery.searchRssItem(params[0]); } @Override protected void onPostExecute(ArrayList<RssItem> result) { rssList.clear(); rssList.addAll(result); rssAdapter.config().notifyDataSetChanged(); } }.execute(s.toString()); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) {} }); txtSearch.setOnKeyListener( new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) return true; return false; } }); switch (v.getId()) { case R.id.btn_manage: startActivityForResult( new Intent(RssReaderActivity.this, RssManageActivity.class), REQ_RSS_MANAGE); break; case R.id.btn_browse: rssProvider = dbQuery.getRssProviderList(null); int length = rssProvider.getProviderNames().length; if (length == 0) break; String[] providers = new String[length + 1]; providers[0] = "All"; for (int i = 0; i < length; i++) providers[i + 1] = rssProvider.getProviderNames()[i]; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder .setTitle(R.string.rss_choose_provider) .setItems( providers, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (item == 0) { loadData(null, true, false, false); return; } loadData(rssProvider.getProviderNames()[item - 1], false, false, false); curProvider = item - 1; updateListView(); } }); builder.create().show(); break; case R.id.btn_refresh: if (curProvider == -1) loadData(null, true, true, true); else loadData( dbQuery.getRssProviderList(null).getProviderNames()[curProvider], false, true, true); break; case R.id.btn_search: if (txtSearchLabel.getText().toString().equals(getString(R.string.btn_search_text))) { btnManage.setVisibility(View.GONE); txtManageLabel.setVisibility(View.GONE); btnBrowse.setVisibility(View.GONE); txtBrowseLabel.setVisibility(View.GONE); btnRefresh.setVisibility(View.GONE); txtRefreshLabel.setVisibility(View.GONE); btnSearch.setBackgroundResource(R.drawable.btn_done_background); txtSearchLabel.setText(R.string.btn_done_text); txtSearch.setVisibility(View.VISIBLE); txtSearch.requestFocus(); } else { btnManage.setVisibility(View.VISIBLE); txtManageLabel.setVisibility(View.VISIBLE); btnBrowse.setVisibility(View.VISIBLE); txtBrowseLabel.setVisibility(View.VISIBLE); btnRefresh.setVisibility(View.VISIBLE); txtRefreshLabel.setVisibility(View.VISIBLE); btnSearch.setBackgroundResource(R.drawable.btn_search_background); txtSearchLabel.setText(R.string.btn_search_text); txtSearch.setVisibility(View.GONE); txtSearch.setText(""); loadData(null, true, false, false); } break; default: break; } }
public void onClick(View v) { ContentResolver cr = getContentResolver(); switch (v.getId()) { // 전부 읽기 case R.id.readall: Cursor cursor = cr.query(Uri.parse(WORDURI), null, null, null, null); String Result = ""; while (cursor.moveToNext()) { String eng = cursor.getString(0); String han = cursor.getString(1); Result += (eng + " = " + han + "\n"); } if (Result.length() == 0) { mText.setText("Empyt Set"); } else { mText.setText(Result); } cursor.close(); break; // 하나만 읽기 case R.id.readone: Cursor cursor2 = cr.query(Uri.parse(WORDURI + "/boy"), null, null, null, null); String Result2 = ""; if (cursor2.moveToFirst()) { String eng = cursor2.getString(0); String han = cursor2.getString(1); Result2 += (eng + " = " + han + "\n"); } if (Result2.length() == 0) { mText.setText("Empyt Set"); } else { mText.setText(Result2); } cursor2.close(); break; // 삽입 case R.id.insert: ContentValues row = new ContentValues(); row.put("eng", "school"); row.put("han", "학교"); cr.insert(Uri.parse(WORDURI), row); mText.setText("Insert Success"); break; // 삭제 case R.id.delete: cr.delete(Uri.parse(WORDURI), null, null); mText.setText("Delete Success"); break; // 수정 case R.id.update: ContentValues row2 = new ContentValues(); row2.put("han", "핵교"); cr.update(Uri.parse(WORDURI + "/school"), row2, null, null); mText.setText("Update Success"); break; } }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); calculator = new Calc(); // main layout LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); layout.setBackgroundColor(Color.BLACK); // upper result box and current opr box container LinearLayout upper = new LinearLayout(this); upper.setOrientation(LinearLayout.HORIZONTAL); upper.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); upper.setGravity(Gravity.TOP); // add the upper layout to the main layout layout.addView(upper); // result box resultbox = new EditText(this); resultbox.setEnabled(false); resultbox.setText(resultStr); upper.addView(resultbox); // middle tier layout LinearLayout middle = new LinearLayout(this); middle.setOrientation(LinearLayout.HORIZONTAL); middle.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); // bottom button grid (numbers 0-9) TableLayout grid = new TableLayout(this); TableRow[] rows = new TableRow[5]; int rownum = 0; for (int i = 0; i <= 12; i++) { // add a new row to the grid if ((i) % 3 == 0 || i == 0) { if (i != 0) rownum = (i) / 3; else rownum = 0; rows[rownum] = new TableRow(this); // TODO: setup row params here grid.addView(rows[rownum]); } Button bttn = new Button(this); if (i < 10) { // integers bttn.setText(Integer.toString(i)); final int _i = i; bttn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // set it so the click changes the string that // you send in the parser and changes the upper textbox if (resultStr != null && resultStr != "") resultStr = resultStr + Integer.toString(_i); else resultStr = Integer.toString(_i); resultbox.setText(resultStr); } }); } else if (i == 10) { // prev answer bttn bttn.setText("."); bttn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // set it so the click changes the string that // you send in the parser and changes the upper textbox if (resultStr != null && resultStr != "") resultStr = resultStr + "."; else resultStr = "."; resultbox.setText(resultStr); } }); } else if (i == 11) { bttn.setText("Clear"); bttn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // Clear the result string resultStr = ""; resultbox.setText(""); } }); } else { // prev answer bttn bttn.setText("Ansr"); bttn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // set it so the click changes the string that // you send in the parser and changes the upper textbox resultStr = prevAnswr; resultbox.setText(resultStr); } }); } rows[rownum].addView(bttn); } middle.addView(grid); /*side button grid (+, -, =, parenthesis, * and %)*/ LinearLayout rightside = new LinearLayout(this); rightside.setHorizontalGravity(RelativeLayout.ALIGN_PARENT_RIGHT); rightside.setVerticalGravity(RelativeLayout.CENTER_IN_PARENT); rightside.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); rightside.setOrientation(LinearLayout.VERTICAL); Queue<String> rightSymbols = new LinkedList<String>(); String[] symbols = {"+", "-", "*", "/", "(", ")"}; List<String> l_symbols = Arrays.asList(symbols); rightSymbols.addAll(l_symbols); while (!rightSymbols.isEmpty()) { final String symbol = rightSymbols.poll(); Button bttn = new Button(this); bttn.setText(symbol); bttn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO add the symbol to the string for submission into the parser if (resultStr != null && resultStr != "") resultStr = resultStr + symbol; else resultStr = symbol; resultbox.setText(resultStr); } }); rightside.addView(bttn); } middle.addView(rightside); // = button, on a bottom bar LinearLayout bottom = new LinearLayout(this); bottom.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); bottom.setLayoutParams(params); bottom.setBackgroundColor(Color.BLUE); Button eqbttn = new Button(this); LinearLayout.LayoutParams eqparams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); eqbttn.setLayoutParams(eqparams); eqbttn.setText("="); eqbttn.setOnClickListener( new OnClickListener() { public void onClick(View v) { // send information to parser and return result as textbox string try { String result = calculator.createResult(resultStr); resultbox.setText(result); resultStr = result; prevAnswr = result; } catch (Exception e) { // TODO Auto-generated catch block resultbox.setText(e.getMessage()); } } }); bottom.addView(eqbttn); layout.addView(middle); layout.addView(bottom); setContentView(layout); }
public void clear() { inputView.setText(""); listAdapter.clear(); listAdapter.notifyDataSetChanged(); }
@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; }