I want to display a recursive or nested text view at depth of 3 in Android.The text to be displayed is, dynamic coming from web service.
for example:
If I Click on Help(Level 1)
it'll show topics under Help
If I Click on Help_Topic_1(Level 2)
it'll show questions under Help_Topic_1
If I click on this question, say HT_Question_1(Level 3)
it'll show Answer of that question(Level 3)
how to accomplish with this? please guide me.
You should use ExpandableListView. Reference http://developer.android.com/reference/android/widget/ExpandableListView.html
You can call expandGroup and collapseGroup methods for expanding and collapsing on clicks.
the simplest way to do this is to have a nested layout structure. Your root view will contain the button to show level 1 and a child layout and initially be visible. The children's layout visibility will initially be set to "GONE". In the onclick listener for each button you change the visibility of the layout below it to view to "VISIBLE".
This of course is a very simple way of doing it. If you require to have open and close animations you'll need to use a more complex method.
Related
I have an EditText in my layout which is used to get the search query from the user. I want to show a LinearLayout bellow it when user enters some characters and fill it with the results (This layout should appear after entering at least N characters). But I don't know how to show this layout?
I thought of putting the whole layout shown in the activity inside a FrameLayout and add the view when required, but there will be two problems:
The view will be added on the top left of the screen.
If I want to move it with adding some padding to it, all the area will correspond to the click event.
To explain what I want more, please take a look at this:
I hope this link will help you, you need to use AutoCompleteTextVIew
http://www.javatpoint.com/android-autocompletetextview-example
https://www.codeofaninja.com/2013/12/android-autocompletetextview-custom-arrayadapter-sqlite.html
These is two approaches for your case.
Use AutoCompleteTextView
Use android-popupwindow.
The former is easier and more acceptable, however if your want to customize the layout of the resulting search, for example arranging them in a gird view, you may what to use the latter option.
Although, AutoCompleteTextView internally uses the latter option.
As per screen 1, I have one Title view, and a listview below it,
I want to place a 'hidden view' above this 'title view' which will be visible only when I have scrolled this list till the top.
I have seen Hide your actionbar
and QuickReturnListView and ObservableScrollView
but as I understand none of them serves my purpose. Do anybody know how to achieve something like this?
You made one of the awesome question. I will just suggest creating one custom layout which will get added into the header of the ListView, and that custom layout contains these two views one is always 'visible' and other view in default 'gone' mode and while the time of refresh makes it 'visible'. or you can use addHeader method while on start and end refresh.
listView.addHeaderView(headerView);
I hope this suggestion will work, "Best of Luck...!!"
"Happy Coding...!!!"
i'm having the next problem.
I have two layouts, one behind the other. When I click on the first view the "click" pass trough the view and it arrives at the second one. How can i stop the onclick only for the first view and enable it when i want at the second view?
Thanks in advance.
EDIT
A image with my problem
2EDIT
Why am i doing this? Because i put im my app a menu like facebook. So i have the menu in the red view and i animate the green to the right to see the complete menu. See http://venturebeat.com/2011/12/07/facebook-for-android-upgraded-with-better-navigation-faster-photo-views/. Seems that the solutions is with set the view clickable to false.
It's not clear what and how do you want to achieve, but it doesn't seem to be a good idea to have RelativeLayouts on top of each other. For this you could use a FrameLayout, or if your layout is a bit more complicated, you could play with setting the views unclickable.
If this doesn't help you, please post some code.
EDIT
It's still not too clear why do you want to achieve this, but you can set the second view unclickable, whenever you want.
Which is the best way to change the content inside a layout by pressing buttons?
I want 6 buttons and different content for each push.
I cannot use tab layout because i already used it so..
I would suggest using the gridview that is set up in API Demos. You can import it in as a new project from the Android SDK.
It works effectively like the list of 'All Apps'. However you can change the way it lays out the buttons/icons/text.
In an app I'm working on, I have a list of message types as buttons. Clicking a button changes the display to a layout for composing the selected message. To do this, I have a FrameLayout for the area I want to change. I reference this view as 'compose_content'. When I want to change the content, I run the following code:
compose_content.removeAllViews();
LayoutInflater.from(activity).inflate(R.layout.new_content,compose_content, true);
This will change the FrameLayout content to the content from the specified layout.
One solution can be to have all the 6 views inside your inflated xml and depending on the button pressed set the visibility of that particular view visible and the rest gone
In my app I want to have a button that if the user clicks it
than a new layout is opened within the current (acually the main) layout.
the new layout should not fill all of the screen and parts of the previous layout
should be grayed out.
Any ideas on how to do this ?
You can show a hidden layout within your button's onClick event by calling
view.setVisibility(View.VISIBLE)
You can also fade out view elements or whole views with
view.setAlpha(75);
view.setBackgroundColor(Color.GRAY);
Note that "view" in the first example is your layout element.. LinearLayout, RelativeLayout, etc. and in the 2nd example, "view" is the element(s) you're trying to gray out.
Follow the answer of SBerg413. And for more information. you can take the relativelayout for the part that you want to hide and display on the button click.
And as like SBerg413 answer. you can hide the respective layout and show the layout you want to display.
Hope it will help you.
Thanks.
you can use a ViewFlipper to achieve what you want, position the viewflipper where the child views should fit (part of the screen you say)..
Inflate the rest of the "child" layouts from other xml, add them to the flipper and switch between them when you want...