I am using three tabs for my application, with each tab showing a number of edittext boxes used for user input. For user convenience, I have some of the same edittext boxes on each screen so that the user doesn't have to go back to tab1 just to enter a value. For example, I have an edittext box on all three tab screens asking for the user's age. I have named the edittext boxes age1 on the tab1 screen, age2 on the tab2 screen, and age3 on the tab3 screen. Then I use code to read which of the three boxes have a value in it, I copy that value ionto the other two edittext boxes.
Is there a way to keep the same edittext box name in all three screens so that a value typed in one shows up in all three, and a single value can be retrieved with a single age.getValue() command?
Each tab nests an Activity, which is its own context.
Since an EditText requires a Context in its constructor, and will only exist in relation to that Context, you can't use it with multiple contexts.
you dont need a activity for every tab
I think you cant add a view twice (but its worth trying )
or you can make a class that extends the editText class lets name it
make a static list in the class (theList)
in the constructor you add each instance to the list
oweride the on text changed method ( or something similar)
and set the text to every item in the list
{
for(EditText e:theList)
e.setText(this.getText());
}
i other words every instance will have the same text
Related
I using this library to make multi state toggleButton
https://github.com/jlhonora/multistatetogglebutton
Everything works fine now.
My issue is how can make the toggle button clicked based on a value given?
Example there are three values in toggle, A,B,and C, which is in Activity B.
I'm passing value A from Activity One to Activity Two. When it comes to Activity Two, the toggle which has value A should be clicked.
It looks like you set the chosen button by it's position. You could retrieve all the texts of the buttons, find the index of the text that matches your text, and then set the chosen button with that index.
Pseudo Code:
val dataFromActivityOne = intent.getString("blah")
multiStateToggle.setValue(multiStateToggle.texts.indexOf(dataFromActivityOne))
I want to send specific rows of listview inside, for example, tab1 and send them to the final tab that is tab6.
So the listview in tab6 is update automatically as i pick rows from other listview.
Now i show you how it looks like my activity: (see the image)
When i switch between tabs i lose variables change inside viewpager
Suppose we have to send "Cosmopolitan" to "Bevande"(Tab). I add quantity with imagebutton to 2 for example, so when i send it to "Bevande"(Tab) i can see the name and the quantity.
Is it possible to do it?
For any code ask me
How can i create an android listview with row 1: textview + spinner row 2: textview + edittext etc.?
I have to make a form and i make it with xml layout but it's too long and bad for perfomance as the eclipse says.
Thank you!
ListView can be used if there is a repetition of same views in every row. This is where you get performance benefits given by adapters' recycling view mechanisms. With every row having different views they cannot be recycled and therefore no point in using the listview there.
So based on what kind of rows you have here are two solutions:
Solution 1:
Row 1 has textview + spinner, Row 2 has textview + EditText. And this combination repeats for the rest of the rows then you can try this. The xml where you create the layout of individual row for the ListView should be made a LinearLayout having two rows. ListView will create the rest of the rows for you by appending this LinearLayout.
Solution 2:
If each row is completely different from other (in terms of views used) then I would suggest using pagination. Divide your form questions into different relevant groups put each group on one page (scrollview). When user answers a set they have to navigate to the next page and so on.
As suggested by #Xaver Kapeller, I'd also suggest not using EditText in a ListView. It is very painful to debug keyboard issues and when the device orientation changes with keyboard open then as well. Instead of EditText ,use TextView which on tapping opens a Dialog box with a EditText. To keep the user interaction minimum.
You can focus the EditText as soon as the dialog open so that keyboard opens and user does not have to tap on the EditText. You can also dismiss the dialog by pressing the imeAction like Done on the soft keyboard or by pressing the hard back button. Dismissing the dialog should trigger a textview.setText("Data entered in the dialog box").
I have a GridView that displays several dozen rows worth of a custom layout, each of which consists of an EditText and a TextView object.
If I understand correctly, I should extend the BaseAdapter class to accomplish that. If so, how can I get access to a specific EditText object?
Also, will recycling of views cause me to lose the text that the user has entered if one of the EditText views is no longer visible?
Is there a simpler means to accomplish what I am describing here (perhaps something other than GridView) ?
When you extend BaseAdapter one of the methods you have to override is getView(...). In this method, you create the view that needs to be shown. If you want to persist text that is entered in the EditText, what you need to do is set a a TextWatcher on the EditText, passing in the position of the EditText (parameter in getView(...)), and whenever the text is changed, save the text in an array of sorts. Then, whenever that position comes back through the getView(...) method, grab the text from the array and populate the EditText.
You should use an underlying data structure ( say a List ) which should hold the data for each element of the Grid.
TextView and EditText should be populated from this List.
I have an application where I have Tab Host. I have certainly four tabs in my Tab Host and one of my tab contains a list of some elements. Now When a user click on the element of the third Tab he is supposed to switched to the first tab and the data of the list element gets displayed there. But when the user initially tries to click on the first Tab without selecting any element from the list of third tab, I need to display the Alert Message that "Please select an item form the List"
I wonder how to do that particularly?
Thanks,
david
use AlertDialog.
Toast.makeText(this,"Please select an item form the List",Toast.LENGTH_LONG).show();
use it on your click event.
You can use any of the above, but I feel its the logic that you're more interested in.
You might be having four different activities for each tab.
Create on more class, which will serve as your Bean class, which holds all the data to transfer information between classes.
Call this class as PrefBean.
Make all its variables static (as of now you'll be using only one to know whether user has selected any list item, and if yes, which one). This way, the variables will be globally available to all of your activities.
Have an integer in PrefBean which depicts whether something is selected or not in your third tab.
The logic goes as this:
Initially, your integer in PrefBean will hold something less than zero (say -1). This will show that nothing is selected as of then.
When user clicks in the first tab, your first activity will be invoked and it should check the value of that integer in PrefBean, display an error message to the user. If the value is negative, means nothing is selected, if its positive, it will give you the position of the row selected. Load anything depending on the row position selected
When user clicks on any row in your third tab's list activity, set your PrefBean integer == the row position selected.
I hope you got the logic