I am trying to make three input edit texts that depend on each other i.e Country, State, City that depend on each other in kotlin android. I want when country is picked in the country input, the states in the selected country should show in the state input.
Any one with an idea how i can achieve this?
I am new to Kotlin and have no idea where to start from
Use conditional the check whether country is selected or not
if(condition){
// condition is true
// You can show and hide views by using: findViewById<EditText>(R.id.myeditText).visibility = View.GONE or View.Visible
} else {
// condition is true
}
These statements will be your best friend
Related
I have a dynamic arraylist that contains String values. I want to match one of its values with AutocompleteText whatever the user has typed/entered. In case the value is not matching with any of the Arraylist values I would like to clear Autocomplete Text.
Couple of Ways I have tried.
Match the typed or user selected value from autocomplete text with list directly without any loop using "contains" method. Didn't achieve the expected result.
Store the values in String[] array from list and loop through it and match it with user input/selection from Autocompletetext. Didn't achieve the result this way too.
Please provide any ideas on how to clear text from autocompletetextview if value is not found?
You did not specify any language that's why i will answer in kotlin
Override onKeyDown method and let's say you will check when enter pressed check if given keycode value equals to KeyEvent.KEYCODE_ENTER
In if block get your text and use an algorithm like below
val arr = intArrayOf(1,2,3) if (textFromTextView !in arr) it means your typed text not in your array and if this condition is true
use autoCompleteTextView.replaceText("") and i hope it will work for you.I never tried but i searched for you.
I use the CountryCodePicker from the CountryCodePickerProject by hbb20.
I get the User's data from the DataBase, and sometimes for whatever reason the User has "" (empty string) saved as their country.
I use this Picker to edit their country, and if the User does not change his country then I get India "IN" as the selectedCCPCountry since the defaultCCPCountry automatically returns India if no country was set.
How can I set the selectedCCPCountry or some other flag to null or "" so that in this case I can know not to change the User's data?
Thanks!
So I created an issue for this on GitHub and got a quick response from the author:
It seems like your primary use case is to select country without phone
number validation, did I get that right? if so, you should try Android
Country Picker (https://github.com/hbb20/AndroidCountryPicker). It has out
of box support for non selection and much more. Please let me know if that
works for you.
Here is my response and my temporary workaround:
As I don't want to undo all the code I have already, I made a temporary workaround.
mCountryChangedByUser is false and turns true only when a country is selected inside the CountryCodePicker.
mCountryCCP.setOnCountryChangeListener(new CountryCodePicker.OnCountryChangeListener() {
#Override
public void onCountrySelected() {
mCountryChangedByUser = true;
mCountryTextTV.setText(mCountryCCP.getSelectedCountryName());
mUser.setCountry(mCountryCCP.getSelectedCountryNameCode());
}
});
If the user did not change his country then just return the original country in my saveUser() function.
if (mCountryChangedByUser) {
userUpdate.setCountry(mCountryCCP.getSelectedCountryNameCode() );
} else {
userUpdate.setCountry(mUser.getCountry());
}
Maybe next time I'll use the AndroidCountryPicker.
Thanks!
I want the user to type in his or her Facebook account-link (don't have a better solution atm).
Now, when the user clicks the edittext it is supposed to say : "www.facebook.com/". Now the cursor is supposed to be at the END of the edittext (after the "/") and the user is not supposed to delete the first letters so that the "www.facebook.com/" stays exactly where it is. This will have the user to ONLY type in his or her facebook name and therefore connect the profile.
Is there a way of doing this?
Thank you :)
You can do that by using the event "TextChanged" and in your code validate if the size is big than your string, like that:
if (((EditText)sender).Text.Length >= 17)
{
((EditText)sender).Text = e.NewTextValue;
}
else
{
((EditText)sender).Text = "www.facebook.com/";
}
So if the value is bigger than your string you will replace that for the value, if not you just set the value with your string
I'm creating a online table reservation app for android. I need to check the availability of a table once a user selects a particular table. For that I am going to use "Dialogs" in android.
I found that dialogs can be customized. See this tutorial.
So I can add a datepicker and get the time from the user from the customized dialog when he selects a particular table. But can I show the result (eg: availability) using the same dialog.
yes you can your dialog in with more than data and views , you can make flag that's represent the state of the code , if
if(flag =="table"){
// change layout and data
dialog.setContentView(R.layout.datatable);
}
else if (flag =="userform"){
// change the layout to userform
dialog.setContentView(R.layout.userform);
}
Okay i have one EditText and one spinner.
My goal is if item 1 on spinner selected the EditText visibility is true, and if item 2 selected EditText visibility is false. what the code for reach that goal ?
i use spiner get selected id like this :
String tipe = spiner.getSelectedItem().toString();
if (tipe=="item2"){
//edittext.visible = false; <-- i don't know how to make/what code this visibility become false
}
Use the below
if (tipe.equals("item2")){ // .equals to compare strings
edittext.setVisibiluty(View.INVISIBLE); //set the visibility
}
Use the below according to your needs
visible 0 Visible on screen; the default value.
invisible 1 Not displayed, but taken into account during layout (space is left for it).
gone 2 Completely hidden, as if the view had not been added.
http://developer.android.com/reference/android/view/View.html#setVisibility(int)
use equals() method for comparing of Two String. It will check the content of the String
String tipe = spiner.getSelectedItem().toString();
if (tipe.equals("item2")){
// do what u want here
}