Skip to content

Instantly share code, notes, and snippets.

imageView.setImageDrawable(ContextCompat.getDrawable(applicationContext, R.drawable.name))
@basarik
basarik / recycleview two columns
Created November 30, 2018 17:43
recycleview two columns and if list size is one, show row as a one column, othervise two columns
//documents -> list of recycleview
val layoutManager = GridLayoutManager(activity, 2)
layoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return if (documents.size > 1) 1 else 2
}
}
@basarik
basarik / format amount
Last active April 11, 2017 07:01
format Amount
private void formatMonthlyIncomeAmount() {
if (etAmount.getText() != null && etAmount.getText().length() > 3) {
String amountString = etAmount.getText().toString();
String formattedString = (amountString.replace(".", "").replace(",", ""));
BigInteger value = new BigInteger(formattedString);
NumberFormat formatWithoutFraction = NumberFormat.getInstance(new Locale("tr", "TR"));
@basarik
basarik / OnlyAllowedCharacterEntry
Created February 15, 2017 14:38
just add your Edittext in XML these codes. You can change the digits you want to.
android:inputType="textNoSuggestions|textVisiblePassword"
android:digits="abcçdefgğhıijklmnoöpqrsştuüvyzABCÇDEFGĞHIİJKLMNOÖPQRSŞTUÜVYZ"
@basarik
basarik / CloseKeyboardWithoutEdittext
Last active February 15, 2017 14:40
to hide keyboard, call the methody. You do not need any edittext
//to hide keyboard, call the method
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
@basarik
basarik / tryParse.java
Last active February 15, 2017 14:35
TryParse
String text = "12";
Double message;
try {
message = Double.valueOf(text);
} catch (NumberFormatException e) {
// did not contain a valid double
message = 0.0;
}
@basarik
basarik / Sort.java
Last active February 18, 2016 13:05
Android Collection sort by Turkish chracters
Collections.sort(stringList, new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
final Collator collator = Collator.getInstance(new Locale("tr_TR"));
return collator.compare(lhs.toUpperCase(), rhs.toUpperCase()); // toUpperCase to avoid a dotless i problem (was at the end)
}
});
}