Inflating a View inside one of two Fragments - android

in my Android application (for tablets), I have a two pane layout. On the left is a fragment containing a navigation menu of sorts, and on the right is a fragment loaded with buttons.
Pressing one of these buttons should result in a AlertDialog popping up. It does, however it pops up over the entire application, instead of just that one fragment. Everything else works perfectly.
I'd be eternally grateful if we could find a solution for this particular issue :)
Thank you!

This question should be what you need. To change the size of your dialog, see this.
Alternatively, you could change the layout of your fragment when the button is clicked, which might be better or look nicer.

I think you can override a dialog to solute this problem

Related

Android Studio multiple fragments

I'm designing a music player app and this is my second time working with android studio and fragments in general. I've watched a lot of tutorial videos on this but I'm having trouble getting multiple fragments to show. Maybe using fragments isn't the way of going about this. But basically what I have right now is a fixed menu at the top and 5 fragments just below it (on top of each other).
What I was hoping to do was by clicking each button one fragment would load so you would have one activity but 5 fragments that load when buttons are pressed. But the issue i'm having right now is instead of stopping one fragment and loading another one, they're being loaded on top of each other. Is there a way to go about doing this?
Below is an image of the design I had in mind. The blue box is where the five fragments are and right now they're overlapping. Any help would be appreciated :)
EDIT: Turns out the answer was I needed to define one layout for all of the fragments. Thanks everyone.
Please post code. But here's what I can make out so far from your problem,
I assume you are just using FragmentManager.beginTransaction.add() again and again.
If it is the case please change your code to
FragmentManager.beginTransaction().replace(
containerViewID,
new FragmentYouWantToReplace
);
What this does is removes previous fragment and adds this new fragment.
So you can have your default fragment using add() during activity load, but for each button click you use replace().
When you call a new fragment you should replace always the same layout, the one you want to show the information, like this:
frag_results frag_results = new frag_results();
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction().replace(R.id.framelayout_secundary, frag_results, frag_results.getTag()).commit();

Swiping between XML layouts in Android

I'm right now working on a launcher app and I have three Activities. User is on 2nd Activity by default and when user swipes left it should take him to 3rd Activity and when user swipes right it should take user to 1st Activity. Just like Swipable Tabs but the Tabs should not appear. Is it possible? Best example is of Home Screen, I want it exactly as Home Screen. I've tried a lot! But I'm not getting what ACTUALLY I want, any help would be gladly appreciated, thanks!
I hope I can get you well.
First personally I don't suggest achieving this goal by using multiple activity. A better way might be one activity containing multiple fragment.
Then if you do so, several tools can make help, ViewPager for example.
If you want to add some view page indicator, as what the homescreen looks like, then ViewPagerIndicator might be a good choice.
Hope it helps.

Display part on another Activity (or Fragment?) Android

I have to deal with two ActionBar displayed at the same time on the screen. There's an onClickListener on the second one which allows the second activity to be shown on the entire screen after a click, with an animation.
I have no idea how to do that. Two activies, fragments? ViewPager? ... Absolutely no idea. Could you please help me? Thank you.
EDIT : here is a picture of what I wanna achieve http://romainpellerin.eu/so_android.png
You have to see it in order to clearly understand my problem.
Definitely Fragments.
When you bring in the second fragment specify animations in the fragment transaction before you commit it.
There are tons of tutorials online. Here some more help.
Android Fragments and animation
SDK
http://developer.android.com/guide/components/fragments.html
how to make fragments backwards compatible
http://developer.android.com/training/basics/fragments/support-lib.html

Android: two activities, one tab

What I want to do is the following:
I have 4 tabs in total, but in 1 tab i want to have multiple screens which the user can change using the menu
I can capture the event of when the user presses the right button, so no help needed there:)
what I can't do is starting the Activity without removing the TabBar!
I found some information about changing the view of the framelayout, but i really want to start another activity in the layout, not just change the view (I want to keep my code clean you see;)
thanks in advance
so in Tab A I want to be able to use Activity A and B
The only solution I found is still replacing the view, but doing it through ActivityGroup, so the code would still look normally and would be separated in activities. Works great, but there still is needs for hacks like back button press and stuff.
Scrapped this idea, though, since later I wanted more flexible and more stylish tab bar, so I wrote my own. Works like a charm and took some 2 working days to code.

Add a view/activity on top of a ListView [Android]

I want to have a view with several choices when I click an element of my ListView. I was thinking of implementing an AlertDialog but as I need more than 3 options it is not possible...
I also thought of putting my ListView in a FrameLayout and have an view with a gone visibility that I would turn visible at the click and update the content but I don't know If it's a good idea.
I could do with some advice,
Thanks for any idea.
You can use ContextMenu, if dialog works fine for you. If you don't want the dialog then use PopupWindow.
You could use ContextMenu
This tutorial may help.
Edit based on the comment:
Hmmm.. Since you want more than 3 options and icons in the menu that's displayed when a item is clicked; you could set an onclicklistener for an item in the list and on clicking switch to an Activity that extends a BaseAdapter along with your own custom layout.
I personally don't recommend this as it could complicate things quite a bit. Context menu is quite straightforward and way to go.
You can create another activity, and give it the dialog theme:
<activity android:theme="#android:style/Theme.Dialog">
This causes it to look like an AlertDialog, but you have full control over what it looks like.
Note that when I used this previously it was rather slow, at least in the emulator though.

Categories

Resources