List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_DONE
int IME_ACTION_DONE
To view the source code for android.view.inputmethod EditorInfo IME_ACTION_DONE.
Click Source Link
From source file:com.llf.android.launcher3.Folder.java
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { dismissEditingName();/*from w w w. ja v a2 s . c o m*/ return true; } return false; }
From source file:com.vaquerosisd.projectmanager.TaskList.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.task_menu, menu); MenuItem searchItem = menu.findItem(R.id.actionBar_SearchTaskItem); Button clearSearchTask = (Button) searchItem.getActionView().findViewById(R.id.actionBar_ClearSearch); final AutoCompleteTextView searchTask = (AutoCompleteTextView) searchItem.getActionView() .findViewById(R.id.actionBar_SearchItemEditText); //Get all tasks names and add them to an adapter for the AutoCompleteTextView List<Task> allTasks = db.getAllTasks(projectId); String[] tasksNames = new String[allTasks.size()]; for (int i = 0; i < allTasks.size(); i++) tasksNames[i] = allTasks.get(i).getTaskName(); ArrayAdapter<String> tasksAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tasksNames);/*from w w w. j av a 2 s.c o m*/ searchTask.setAdapter(tasksAdapter); searchTask.setThreshold(1); //Clear text of search AutoCompleteTextView clearSearchTask.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { searchTask.setText(""); } }); searchTask.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); } else { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } } }); //Search task searchTask.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { //When the user press "DONE" key, select the task if (actionId == EditorInfo.IME_ACTION_DONE) { String project = searchTask.getText().toString(); searchTask(project); //Hide keyboard InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(searchTask.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); return true; } return false; } }); return true; }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentKoopman.java
/** * Trigger the autocomplete on enter on the erkennings- en sollicitatenummer search textviews * @param view the autocomplete textview * @param actionId the type of action//w w w . ja v a2s .co m * @param event the type of keyevent */ @OnEditorAction({ R.id.search_erkenningsnummer, R.id.search_sollicitatienummer }) public boolean onAutoCompleteEnter(AutoCompleteTextView view, int actionId, KeyEvent event) { if (((event != null) && (event.getAction() == KeyEvent.ACTION_DOWN) && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { showDropdown(view); } return true; }
From source file:org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin.java
private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) { int keyEvent = specialKeyMap.get(key, 0); if (keyEvent == 0) return false; InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection(); // Log.d("RemoteKeyboardPlugin", "Handling special key " + key + " translated to " + keyEvent + " shift=" + shift + " ctrl=" + ctrl + " alt=" + alt); // special sequences: if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) { // Ctrl + right -> next word ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0); int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT); if (pos == -1) pos = currentTextLength(extractedText); else//from www .j a v a 2 s .c o m pos++; int startPos = pos; int endPos = pos; if (shift) { // Shift -> select word (otherwise jump) Pair<Integer, Integer> sel = currentSelection(extractedText); int cursor = currentCursorPos(extractedText); // Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor); startPos = cursor; if (sel.first < cursor || // active selection from left to right -> grow sel.first > sel.second) // active selection from right to left -> shrink startPos = sel.first; } inputConn.setSelection(startPos, endPos); } else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) { // Ctrl + left -> previous word ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0); int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT); if (pos == -1) pos = 0; else pos++; int startPos = pos; int endPos = pos; if (shift) { Pair<Integer, Integer> sel = currentSelection(extractedText); int cursor = currentCursorPos(extractedText); // Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor); startPos = cursor; if (cursor < sel.first || // active selection from right to left -> grow sel.first < sel.second) // active selection from right to left -> shrink startPos = sel.first; } inputConn.setSelection(startPos, endPos); } else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) { // Shift + up/down/left/right/home/end long now = SystemClock.uptimeMillis(); inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0)); inputConn.sendKeyEvent( new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON)); inputConn.sendKeyEvent( new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON)); inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0)); } else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) { // Enter key EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo(); // Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions); if (editorInfo != null && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) { // Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?) // check for special DONE/GO/etc actions first: int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND, EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_DONE }; // note: DONE should be last or we might hide the ime instead of "go" for (int i = 0; i < actions.length; i++) { if ((editorInfo.imeOptions & actions[i]) == actions[i]) { // Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]); inputConn.performEditorAction(actions[i]); return true; } } } else { // else: fall back to regular Enter-event: // Log.d("RemoteKeyboardPlugin", "Enter: normal keypress"); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent)); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent)); } } else { // default handling: inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent)); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent)); } return true; }
From source file:org.telegram.ui.ChannelEditTypeActivity.java
@Override public View createView(Context context) { actionBar.setBackButtonImage(R.drawable.ic_ab_back); actionBar.setAllowOverlayTitle(true); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override/* w w w. j av a 2 s . c om*/ public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (donePressed) { return; } if (!isPrivate && ((currentChat.username == null && nameTextView.length() != 0) || (currentChat.username != null && !currentChat.username .equalsIgnoreCase(nameTextView.getText().toString())))) { if (nameTextView.length() != 0 && !lastNameAvailable) { Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(200); } AndroidUtilities.shakeView(checkTextView, 2, 0); return; } } donePressed = true; String oldUserName = currentChat.username != null ? currentChat.username : ""; String newUserName = isPrivate ? "" : nameTextView.getText().toString(); if (!oldUserName.equals(newUserName)) { MessagesController.getInstance().updateChannelUserName(chatId, newUserName); } finishFragment(); } } }); ActionBarMenu menu = actionBar.createMenu(); menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); fragmentView = new ScrollView(context); fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background)); ScrollView scrollView = (ScrollView) fragmentView; scrollView.setFillViewport(true); linearLayout = new LinearLayout(context); scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); linearLayout.setOrientation(LinearLayout.VERTICAL); if (currentChat.megagroup) { actionBar.setTitle(LocaleController.getString("GroupType", R.string.GroupType)); } else { actionBar.setTitle(LocaleController.getString("ChannelType", R.string.ChannelType)); } LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.VERTICAL); linearLayout2.setElevation(AndroidUtilities.dp(2)); linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1 = new RadioButtonCell(context); radioButtonCell1.setElevation(0); radioButtonCell1.setBackgroundResource(R.drawable.list_selector); if (currentChat.megagroup) { radioButtonCell1.setTextAndValue(LocaleController.getString("MegaPublic", R.string.MegaPublic), LocaleController.getString("MegaPublicInfo", R.string.MegaPublicInfo), !isPrivate, false); } else { radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), !isPrivate, false); } linearLayout2.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!isPrivate) { return; } isPrivate = false; updatePrivatePublic(); } }); radioButtonCell2 = new RadioButtonCell(context); radioButtonCell2.setElevation(0); radioButtonCell2.setForeground(R.drawable.list_selector); if (currentChat.megagroup) { radioButtonCell2.setTextAndValue(LocaleController.getString("MegaPrivate", R.string.MegaPrivate), LocaleController.getString("MegaPrivateInfo", R.string.MegaPrivateInfo), isPrivate, false); } else { radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), isPrivate, false); } linearLayout2.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); radioButtonCell2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isPrivate) { return; } isPrivate = true; updatePrivatePublic(); } }); sectionCell = new ShadowSectionCell(context); linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); linkContainer = new LinearLayout(context); linkContainer.setOrientation(LinearLayout.VERTICAL); linkContainer.setElevation(AndroidUtilities.dp(2)); linkContainer.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background)); linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); headerCell = new HeaderCell(context); headerCell.setElevation(0); headerCell.setBackground(null); linkContainer.addView(headerCell); publicContainer = new LinearLayout(context); publicContainer.setOrientation(LinearLayout.HORIZONTAL); linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0)); EditText editText = new EditText(context); editText.setText("telegram.me/"); editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); //editText.setHintTextColor(0xff979797); editText.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); editText.setMaxLines(1); editText.setLines(1); editText.setEnabled(false); editText.setBackgroundDrawable(null); editText.setPadding(0, 0, 0, 0); editText.setSingleLine(true); editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); editText.setImeOptions(EditorInfo.IME_ACTION_DONE); publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36)); nameTextView = new EditText(context); nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); if (!isPrivate) { nameTextView.setText(currentChat.username); } //nameTextView.setHintTextColor(0xff979797); nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text)); nameTextView.setMaxLines(1); nameTextView.setLines(1); nameTextView.setBackgroundDrawable(null); nameTextView.setPadding(0, 0, 0, 0); nameTextView.setSingleLine(true); nameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); nameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE); nameTextView.setHint( LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder)); AndroidUtilities.clearCursorDrawable(nameTextView); publicContainer.addView(nameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36)); nameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { checkUserName(nameTextView.getText().toString()); } @Override public void afterTextChanged(Editable editable) { } }); privateContainer = new TextBlockCell(context); privateContainer.setForeground(R.drawable.list_selector); linkContainer.addView(privateContainer); privateContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (invite == null) { return; } try { android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext .getSystemService(Context.CLIPBOARD_SERVICE); android.content.ClipData clip = android.content.ClipData.newPlainText("label", invite.link); clipboard.setPrimaryClip(clip); Toast.makeText(getParentActivity(), LocaleController.getString("LinkCopied", R.string.LinkCopied), Toast.LENGTH_SHORT) .show(); } catch (Exception e) { FileLog.e("tmessages", e); } } }); checkTextView = new TextView(context); checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT); checkTextView.setVisibility(View.GONE); linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7)); typeInfoCell = new TextInfoPrivacyCell(context); //typeInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); loadingAdminedCell = new LoadingCell(context); linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); adminedInfoCell = new TextInfoPrivacyCell(context); //adminedInfoCell.setBackgroundResource(R.drawable.greydivider_bottom); linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT)); updatePrivatePublic(); return fragmentView; }
From source file:com.google.android.apps.flexbox.FlexItemEditFragment.java
private void setNextFocusesOnEnterDown(final TextView... textViews) { // This can be done by setting android:nextFocus* as in // https://developer.android.com/training/keyboard-input/navigation.html // But it requires API level 11 as a minimum sdk version. To support the lower level devices, // doing it programatically. for (int i = 0; i < textViews.length; i++) { final int index = i; textViews[index].setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override//from w ww. j ava2s . c o m public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_DONE || (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { if (index + 1 < textViews.length) { textViews[index + 1].requestFocus(); } else if (index == textViews.length - 1) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); } } return true; } }); // Suppress the key focus change by KeyEvent.ACTION_UP of the enter key textViews[index].setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { return keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP; } }); } }
From source file:com.android.ex.chips.RecipientEditTextView.java
@Override public boolean onEditorAction(final TextView view, final int action, final KeyEvent keyEvent) { if (action == EditorInfo.IME_ACTION_DONE) { if (commitDefault()) return true; if (mSelectedChip != null) { clearSelectedChip();/*from w w w.j ava 2 s. c om*/ return true; } else if (focusNext()) return true; } return false; }
From source file:co.carlosjimenez.android.currencyalerts.app.MainActivityFragment.java
/** * Helper method to obtain the main currency from the shared preferences and set the information * on the top frame./*from w ww. ja v a 2s . c o m*/ */ public void loadMainCurrencyDetails() { mCurrencyEditText.setPrefix(mMainCurrency.getSymbol()); mCurrencyEditText.setSelection(mCurrencyEditText.getText().length()); mCurrencyEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_GO || actionId == EditorInfo.IME_ACTION_DONE) { calculateRates(); handled = true; } return handled; } }); Glide.with(this).load(mMainCurrency.getCountryFlag()).error(R.drawable.globe).centerCrop().crossFade() .into(mImageView); mImageView.setContentDescription(Utility.formatCountryFlagName(mContext, mMainCurrency.getCountryName())); mCurrencyDescription.setText(mMainCurrency.getName()); mImageView.setContentDescription(mMainCurrency.getName()); }
From source file:com.android.ex.chips.RecipientEditTextView.java
@Override public InputConnection onCreateInputConnection(final EditorInfo outAttrs) { final InputConnection connection = super.onCreateInputConnection(outAttrs); final int imeActions = outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION; if ((imeActions & EditorInfo.IME_ACTION_DONE) != 0) { // clear the existing action outAttrs.imeOptions ^= imeActions; // set the DONE action outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE; }/*from w ww . j a va 2 s .c om*/ if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION; outAttrs.actionId = EditorInfo.IME_ACTION_DONE; outAttrs.actionLabel = getContext().getString(R.string.done); return connection; }
From source file:com.example.sadashivsinha.mprosmart.Activities.AllVendors.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.fab_add: { Intent intent = new Intent(AllVendors.this, AddVendorsActivity.class); startActivity(intent);/*from w w w . j a v a2s .c o m*/ } break; case R.id.fab_search: { AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Search Vendor by Vendor Name or ID !"); // Set an EditText view to get user input final EditText input = new EditText(this); input.setMaxLines(1); input.setImeOptions(EditorInfo.IME_ACTION_DONE); alert.setView(input); alert.setPositiveButton("Search", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (input.getText().toString().isEmpty()) { input.setError("Enter Search Field"); } else { Intent intent = new Intent(AllVendors.this, AllVendors.class); intent.putExtra("search", "yes"); intent.putExtra("searchText", input.getText().toString()); Log.d("SEARCH TEXT", input.getText().toString()); startActivity(intent); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Toast.makeText(AllVendors.this, "Search cancelled .", Toast.LENGTH_SHORT).show(); } }); alert.show(); } break; case R.id.exportBtn: { //csv export int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion > android.os.Build.VERSION_CODES.LOLLIPOP) { if (ContextCompat.checkSelfPermission(AllVendors.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(AllVendors.this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 1); } Environment.getExternalStorageState(); String vendorId = null, vendorName = null, vendorTypeId = null, decipline = null, taxID = null, license = null, companyName = null; int listSize = vendorList.size(); String cvsValues = "Vendor ID" + "," + "Vendor Name" + "," + "Vendor Type ID" + "," + "Discipline" + "Tax ID" + "," + "Licence" + "," + "Company Name" + "\n"; for (int i = 0; i < listSize; i++) { AllVendorList items = vendorList.get(i); vendorId = items.getVendor_id(); vendorName = items.getVendor_name(); vendorTypeId = items.getVendor_type(); decipline = items.getDiscipline(); taxID = items.getText_tax_id(); license = items.getText_licence_no(); companyName = items.getText_company_name(); switch (decipline) { case "1": decipline = "Electrical"; break; case "2": decipline = "Mechanical"; break; case "3": decipline = "Civil"; break; case "4": decipline = "Architectural"; break; } cvsValues = cvsValues + vendorId + "," + vendorName + "," + vendorTypeId + "," + decipline + taxID + "," + license + companyName + "\n"; } CsvCreateUtility.generateNoteOnSD(getApplicationContext(), "Vendors-data.csv", cvsValues); } else { Environment.getExternalStorageState(); String vendorId = null, vendorName = null, vendorTypeId = null, decipline = null, taxID = null, license = null, companyName = null; int listSize = vendorList.size(); String cvsValues = "Vendor ID" + "," + "Vendor Name" + "," + "Vendor Type ID" + "," + "Discipline" + "Tax ID" + "," + "Licence" + "," + "Company Name" + "\n"; for (int i = 0; i < listSize; i++) { AllVendorList items = vendorList.get(i); vendorId = items.getVendor_id(); vendorName = items.getVendor_name(); vendorTypeId = items.getVendor_type(); decipline = items.getDiscipline(); taxID = items.getText_tax_id(); license = items.getText_licence_no(); companyName = items.getText_company_name(); switch (decipline) { case "1": decipline = "Electrical"; break; case "2": decipline = "Mechanical"; break; case "3": decipline = "Civil"; break; case "4": decipline = "Architectural"; break; } cvsValues = cvsValues + vendorId + "," + vendorName + "," + vendorTypeId + "," + decipline + taxID + "," + license + companyName + "\n"; } CsvCreateUtility.generateNoteOnSD(getApplicationContext(), "Vendors-data.csv", cvsValues); } } break; } }