Afternoon guys, my problem is:
I have a main tab that contain a 'Search' button, when it's pressed it should load data from the database (which is OK) and apply it to all the tabs (here's the problem)
How an i supposed to do this, is it possible?
If it's not possible, is there any way to pass info trought tabs? Like the customer ID so i could search his info whenever the tab changes?
Thx
Ye is possible. Save the content in one global variable and use it in the next tab. In your case if it is string save declare one private/public string variable outside the tabs, when is needed assign data to the string, and use it in the same in the next tabs or whatever you want.
Related
I have 3 different layouts in Activity, with a lot of fields. right now I use Tab layout, ViewPager2, Fragments in my activity for load these 3 Fragments that contain too many fields (that in the end all of the text in these fields must aggregate into one JSON Object or data class). I disabled on touch event for Tab Layout and swipe for ViewPager and use 2 buttons in bottom layout activity (for validating current fragment's fields). these 2 buttons used for next, previous, back to home, and submit. (Actually, I have 2 buttons and handle text and functionality for these buttons with View Pager position). everything works correctly unit now except this, I need to aggregate all fields into one JSON or data class in these different Fragments as one JSON Object or data class.
my question is:
Is there a better way to handle this scenario or this one is good?
(Considering that, in the submit button, I must get all value from fields into 3 different fragments and save into one data class then send it into another Fragment or Activity and save into SQLite database with room and my problem is here too. how I must handle it for clean code and good performance)
thanks for your help
im new to programming.. i'm building an app with a about 18 buttons.. after clicking the button it takes me to a new activity..
the new activity layout is the same for all the buttons but i want to change the text (title and text).
e.g. activity1 is a list of buttons of football clubs (Barcelona, Madrid,...etc). once clicked it will take you to activity 2 which displays the information about the club (text).
Must i create an activity for each of all 18 buttons? (imagine if each button has a few more buttons and that will multiply to over 50 activities and all the classes asociated with them)
Is there a way i can code my target page to use the same layout but just pull different stings of text which corresponds to the button?
Appreciate all the help.. thanks allot!
It sounds like you want to change only text.so you can keep track of which button is clicked in your previous activity.
You can store that value you are using to keep track which button clicked into
1)SharedPreference and retrive into another activity link for how to use it.
2)Intents -Store value into intent and pass to another activity and retrive it.(You can use bundle too here) link for how to use it
After retriving value you can use setText("") function hope it will help you
Just start the same Activity again and keep some kind of index either in the Application class, a Database or SharedPreference use this index to keep track of what you should be displaying in each instance of the same Activity.
You can start the same Activity as many times as you want and it will still be treated as a separate one and the back stack will still function the same.
Use same Activity and same layout and pass some indicator to activity or pass title and text from current activity to next activity and display title and text accordingly
I have an app where the user has to fill up a form. It has many text views, edit texts, and radio buttons.
If i replace that fragment later, how do I preserve the data if i go back to that replaced/previous fragment?
There are many options available. Try any of them.
Option 1: Use Shared Preferences
Saving Key-Value Sets
Option 2: Use Parcelable
Android Parcelable Example – Passing data between activities
Option 3: Use Fragment Save Instance State
Probably be the best way (?) to save/restore Android Fragment’s state so far
Now I want to create a TabHost for 3 categories, Pizza, Spaghetti and Snack. Information will be taken form database. Is it possible to access only information of that specific category after the tab is clicked instead of creating it when the activity starts. If it is possible, which way is better.
I made something like you over a week ago and after long debugging I realized that the system loads the present tab and the one after it at the same time in case to be ready for swiping anytime you wanna do it (I mean their layouts). So if you place your database logic on the Fragments not on your Activity directly (different database logic on the different tabs), when you load your app, only the first tab database logic will be loaded, but the second tabs layout will be loaded too. Hopefully you could understand what I meant :)
I'm a newbie Android developer and I'm trying to create an Android application with 2 tabs, using Activities for each tab. This is basically how it should work:
Tab A has 1 button
Tab B has 1 ListView
When the user clicks on the button in Tab A the application must put a value in the ListView in Tab B
My question is: how can I update the ListView in Tab B when I click on the button in Tab A? I know how to put values in a ListView when it's on the same tab where the button is located but my approach doesn't work when the ListView is in a different tab. I tried...
ListView myListInTabB = (ListView)findViewById(R.id.list_on_tabB);
but didn't work :-/
Any suggestion?
Thanks in advance.
Im not sure you actually need seperate activites for this, unless you are doing some specific work between your activities. Most tab solutions you see in Android solutions work simply by hiding the Views that are not related to the current shown tab. You will find the "visibility" property helpful for making this happen. Also, making sure all of your Views are in the same Activity lets you access their objects all the time, regardless of their visibility.
You don't do that. Just ensure the underlying Adapter has the latest data. Calling requery() on the Cursor does the trick, it automatically updates the ListView attached to it.
Edit: use notifyDataSetChanged() to let the list know that the data is stale.