Force Fragment refresh on tab change - java

I have two tabs. In the second one I have a SeekBar and a save button. When the save button is pressed, I save the SeekBar value and switch to the first tab using this in the save button click listener.
getActivity().getActionBar().setSelectedNavigationItem(0);
The Fragment at the position 0 has a ListView that gets values from SQLite database. That's the place where the SeekBar value was saved in the second Fragment. How do I make this Fragment refresh when the save button is pressed so that the changes are shown?

How do I make this Fragment refresh when the save button is pressed so that the changes are shown?
Just tell it to do that using interface of your design this fragment should implement.
mySecondFragment.refreshStuffPlease();

On tab press call the notifyDatasetChanged method of Base adapter of the ListView.
listadapter.notifyDatasetChanged()

Related

after returning back from my second Activity to first Activity on clicking button the whole data is gone

I have two activties:
activity_main,
activity_display
in the main_activity user enters his/her name and presses the toggle button to display.
that takes the user to display_activity page where the result is displayed.
if the user finds that he/she has entered the wrong info they can go back and edit.
here is where the problem starts
after pressing the toggle button - display
it goes to display_activity and displays but when I press "back" button I'm restarting the whole (first) main_activity again... no values are present...
even the toggle button that needs to be set to "reset" is again showing "display".
should i use something else instead of
startActivity(intend1);
i want to resume the (first) activity main not restart everything
Seems like your first activity uses results from second activity. you can use startActivityForResult. Here is a very good answer refer to it.
How to manage startActivityForResult on Android

How do I save the state of fragments in android?

I'm using a bottom navigation view which has 2 menu items. Each menu item upon clicking loads a fragment onto the MainActivity.
The first fragment is the home fragment where a RecyclerView shows a list of items and the second fragment contains a simple form.
now whenever I switch back and forth between these fragments, their previous states are lost and the fragment is recreated. This is a big issue for me because suppose I scroll to, let's say the 15th item of the list present in the home fragment. After scrolling, I navigate to the second fragment and then I navigate back. What happens is that the home fragment gets recreated and to see the 15th item I have to scroll again.
What should I do to handle this?

Android Java Fragment Button save

I got 2 Fragments. In the first Fragment I got a button.
How is it possible to duplicate the button on the second Fragment when the user click on it.
What do you mean by duplicating a Button? If it means creating a Button with the same text or other layout attribute, you can create a method in the second Fragment, like createButton(String text, int color), to add the button dynamically. When the button is clicked, find the second Fragment, cast it to the class of second Fragment and call the createButton method.

Android change in view - Button state gets reset

I have a button which is basically used for start/stop. So initially the text of the button is set to start. I attached a OnClickListener to it. So whenever it gets clicked i change its text. So if it was start it become stop and vice-versa.
The problem comes when i change my phone view from portrait to landscape or vice-versa the button text gets reset.
So for example I clicked the start button---it changed to stop. Now if I tilt my phone to change the view the button text gets set to start again.
Am I using the button in a wrong way?
You should save your button state. When screen orientation changes, onCreate is called and all your app variables are re-intitialized. Read more here http://developer.android.com/reference/android/app/Activity.html
No, you are using the button in the right way.
The thing what you are seeing is "configuration change". When you are tilting your device, Android recreating your activity and recreating all it's views (so, they getting default captions as them described in XML).
You need to do the
disable configuration changes for your Activity. To do so, add the following to your manifest's activity tag: android:configChanges="orientation|keyboardHidden". It is not suitable, if you have different layouts for landscape and portraint orientations, when you need to...
handle the configuration changes by overriding onSaveInsatnceState method of your Activity, save a state there and then use it in onCreate method.
See this article for further explanation

Can I show up the textbox editor on an image icon in Android?

all,
We know on Andorid, for a EditText, by default, whenever the EditText is clicked, the soft keyboard pops up to let you enter text. When you click DONE, it closes out and put the text directly to the EditText.
Now, what I am trying to do is, instead of an EditText, I have an ImageView which is to let user enter some comment.(So the ImageView actually is an comment icon). I wish whenever the icon is clicked, it pops up the text editor with user previous entered text, again once the DONE is hit, it closes out and I can save whatever text there back to a string member of the Activity. Is that possible?
So far, all I've seen about InputMethodManager is on EditText control, If it is too complicated, I probably just put an EditText into a sperate Activity.
Thanks.
There are many solutions:
One is to use custom dialog: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
Second one is to use a transparent activity on top of that one.
Then you could use FrameLayout and insert another view in an exact position...
I think you should try the frist or second one. Every ImageView can be easily converted into a button by adding onClick event to it.

Categories

Resources