Android Java Fragment Button save - java

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.

Related

1 Button 2 activity in android studio using java

How do I open another activity with the same button I clicked earlier? For example, I click button A and goes to Activity 1 and I click home and click button A again and must go to Activity 2.
I tried putting id on button in xml and call different activity on its java.
Imagine if the button is from HomeActivity,let the launcher activity pass an ExtraKey to the HomeActivity and again another ExtraKey at the OnBackPressed of the Activity you are navigating to after clicking the button.Set the onClickListner according to the String passed by those activities.

Views in fragment not showing up when fragment is popped from backstack

I have two fragments: one for entering names, and one that uses the list of names. On the second fragment there is a previous button to go back to the first fragment to edit the names. When the "previous" button is pressed, every programmatically generated EditText disappears, except for the one specified in the xml.
The first fragment before pressing next
The second page with the previous button
The first fragment after previous is pressed
This is how I'm inflating the Edittexts:
EditText editText = (EditText)getActivity().getLayoutInflater().inflate(R.layout.edittext,null);
editText.setHint("Roommate " + counter);
editText.requestFocus();
layout.addView(editText);
I've tried re-inflating completely new edittexts which still do not show up. Any suggestions would be fantastic
EDIT: Instead of replacing fragment 1 with fragment 2 I tried using getSupportFragmentManager().add(...) instead of .replace(...) and It now works as it should

Force Fragment refresh on tab change

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()

Adding another line of components to relativelayout

Anyone know how to get this result?
Description:
When the '+' button is clicked, another line of EditText, Spinner, EditText and Button will be displayed below the line. And lines go on adding if the user click on the '+' button.
Thanks!
I think the best would be to implement a custom ViewGroup extending a LinearLayout in vertical orientation.
You'll register an OnClickListener on the last button: if the row is the last in the list, you'll inflate a new ingredients_item.xml and add it to your view (also you'll refresh the drawable from + to -), otherwise remove the current row.
Your custom view will provide a method like List<Ingredient> getIngredients(), so you'll be able to pass this list to some save() method.
I pushed the demo on GitHub

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