When the user hits a button in my app, it shows a persistent single-choice-list with use of AlertDialog.Builder and the setSingleChoiceItems()-method. The list is populated with values from a simple array, which is not known at compile-time. When the user hits "OK" in the dialog, the value is saved.
Now, I would like an option in this list where the value is a textbox and not populated from the array. Is this anyhow possible, and which way should I go?
I've tried to sketch it here:
[] option a
[] option b
[] option c
[] "TEXTBOX HERE"
Well it can get complicated but, here it is..
You can add onClickListener to that radiobutton and set its text like "Enter the text".
Then, in in onclick() open a custom dialog box which accepts text. then set value received from there in your radio button text by radioButt.setText(value entered);.
Custom Dialog example. in here just add editText in place of image view and text view.
Related
I have two numberpicker and a submit button. I like to fade out or something like that when a value is selected and submit button is clicked.
So if number 20 is selected it will not be available next time.
Is this possible with Android numberpicker?
Please check this thread, on how to customize values of a NumberPicker in Android:
How to customize value for numbers in NumberPicker in android?
Once you know how to customize values it is trivial. On the item selected event (or in your case on click of "submit button") remove the value from the list of the custom values and update the NumberPicker.
I would like to know how to read the contents of a text file line by line and add it to a ListView in Android.
Look at my scenario:
I have three activities-add_new, show and show_all. In the "add_new" activity, there are two EditText fields and a button. When I enter text in both the EditText fields and press the button, it should be stored as two separate lines in a text file in the Android filesystem.
The "show_all" activity contains a ListView, which populates the contents of the text file in such a way that, the one line is shown as the title (the content read from the first EditText field) of each item, and the immediate next line (the data read from the second EditText field) is the data associated with it in the listview.
When I click any item in the ListView, a new activity, "show" displays the details ofthat particular item. When I press delete button in that activity, the original text file need to be updated in such a way that, the lines associated with that item need to be deleted.
How do we do this?
in may application, i have a spinner widget that contains huge amount of data.
it is hard for user to find his item between them, so i decided to insert search capability for content of spinner.the idea is If the user taps the quick search button he should be provided with a text field to enter a letter and then the spinner list jumps to the fist word it finds with the letter supplied.
is there any solution to that?
thanx
Let us assume, full Spinner data is list.
Initialize
listCurrent=list.clone();
set ArrayAdapter on spinner by
ArrayAdapter<String> adapter=new ArrayAdapter(context, android.R.layout.simple_spinner_item_1, listCurrent);
override onTouch event, open dialog containing edit text say editText and a button on tap, else select item, in dialog button click, get String from editText and filter results and reset adapter by invoking:
listCurrent= filter(list, text);
adapter.notifyDataSetChanged();
Easy way to do things you want is
Have an Button which contain the Text of Selection.
When the Button is clicked Open the Dialog or Activity(startActivityForResult) containing the ListView with EditText.
update the listview with the Searched content in EditText.
When user click on an Item in the ListView. finish the Activity with result.
and update the Text in Button from onActivityResult.
You can use auto-compilation...
I have a problem that I have two spinners, second spinner is dependent on first (means when I select a item from 1st Spinner then according to that Second Spinner gets filled). But the problem is, I want Select Keyword as a default Item for both spinners, and when I will click on that, spinner should filled with parsed Info and when I will select an Item from first Spinner then the Parsing starts for Second Spinner but Spinner remains with default Select Keyword, when I will click on second spinner then it should be filled by the parsed Info.
How can I implement this, because when I am setting the adapter in any spinners its onItemSelectedListner first called, which is not desirable.
You will need to add "Select" as your first item in your array list..
and on click event of the Spinner you just remove the First item from your array list
you will also find many similar question in Stack Overflow..search for it and you will get your exact answers with example.
You Can do this by Dialog, make a Customize dialog with List Box and fill the list with parsed data after click on TextBox which contains Select Keyword as a default.
I have a static radiogroup in my XML layout, but I have created all of the radiobuttons dynamically as an effect of user input. Since none of these have ID's, is there a way I can call a method on a whole radiogroup to just return the text (or label) of the checked radio button? All the labels are URL's so if I can get the URL of the checked radio button then I can pass it to a method i created to open the web browser.
I can use ID's but then I would have to create a bunch of extra text for the radio button labels anyways, then a bunch of if statements with the labels written a second time.. [ if this ID is selected go to this URL, if this ID is open go to this URL...] Where as I just want to take the RadioButton's label and just put it right into the browser method.
I found this post: Android: How to get text of dynamically created radio button selected by the user?
but it wasn't answered correctly.
Thanks in advance.
If IDs are no good for you, maybe you should use the tag property that all Views have, i.e. call radioButton.setTag(url) when you create the button. Then call View.getTag() in your onClickListener and cast to a String to get your URL back.