I have 3 Buttons, 3 Scroll Views, and some Textviews and pictures and what not.
The 3 Buttons I want to be able to show a different Scroll View when they are clicked.
So clicking Button #1 would show Scroll View #1 and hide Scroll View #2 & #3
etc....
Is there a way to do this programmatically? Like in an OnClick() Event?
you can use the setVisiblility() method:
mScrollView.setVisibility(View.GONE);
by setting View.GONE you'll view will become invisible, and will not take any actual space inside the layout container it reside in.
then when you'll want to make it visible again, use the:
mScrollView.setVisibility(View.VISIBLE);
Use ExpandableListview For that
Refer this Links this will help to Implement ExpandableListview in android
http://androidword.blogspot.in/2012/01/how-to-use-expandablelistview.html
http://androidtrainningcenter.blogspot.in/2012/07/android-expandable-listview-simple.html
http://android-adda.blogspot.in/2011/06/custom-expandable-listview.html
Related
I have a recycler view which has its items in a card view. The recycler view gets its data from a sql database within the app . Now I want to implement two features to this recycler view items. First , whenever the individual cards are tapped , I want them to enlarge and display more data and should shrink back when tapped again. It is not like the case of expandable list view where it expands into a child list view. I want the height of the card to increase and just show some more information and buttons. Second I want the items to swipe left . I know there is a feature for that in recycler view , but I want to customise the swipe feature. Swipe from right should be locked , and when swiped from left , It should not go off list completely. It should show two buttons and should go off list only when one of the buttons is clicked. I have been looking , but there is no proper explaination anywhere. Please guide me through this process.
For your first question, set the adapter layout_height to wrap_content and set the buttons visibility to GONE. Implement the OnClick listener in the RecyclerView adapter and set the visibility of the buttons to VISIBLE if GONE and GONE if VISIBLE or use a boolean to alternate the visibility.
For your second question, this might help:
https://www.learn2crack.com/2016/02/custom-swipe-recyclerview.html
How can I make my Android SwipeableCardViews more like the IOS 7 mail app (swipe to show buttons)
https://github.com/daimajia/AndroidSwipeLayout
I have 40 ImageViews inside a GridLayout, they have different colors and I want to know if user touched the desirable image or somewhere else(for example if user touched red image). How should I do that?
Set an OnClickListener for each view and store the views. In onClick you can check the view and know what ImageView was clicked. You could also think about changing the type to ImageButtons!
If you have further problems with your Grid not being able to be clicked, check this out: http://cyrilmottier.com/2011/11/23/listview-tips-tricks-4-add-several-clickable-areas/
TLDR: Disable focusing of the views in your layout.
If you manage your images in a collection maybe think about switching to gridview and implement an adapter with an itemClickListener. So depend on which item is clicked do you action.
How GridLayout items come from the Adapter(List/Image) in Android App
I have layout containing 30 fields ( using editbox, spinners, buttons etc)
but it looks too weird with crowded elements. ( scroll view is also longer)
So i decided to keep 1 more button, so firstly 15 fields will display and 1 "More" button below,now i want to display rest of fields onClick "more" button on same layout ( below that 15 fields). How to do this, thanks in advance
I would suggest you to make a parent view with two main relative layouts. First relative layout for all the content you want to show at first time. Make this layout visibility View.VISIBLE. Second relative layout for all the content you want to show on click event. Make this layout visibility View.INVISIBLE.
On button click event make second relative layout visible by setting view.setVisibility(View.VISIBLE)
Don't forget the invisible the layout in the end. Otherwise it will be visible throughout the app session.
You can also set this property in your xml too. There is a android:visibility="visible" tag in every view.
This approach will help you in management because by setting a single view visibility you can manage your all view. Happy Coding!!
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.
I jave a list of item (linearlayout inside a scrollview where i add buttons vertically to linearlayout dynamically from the java code ) ? i need when i click on one button the item moves up (scroll up) , to make the item at the first of the screen ??!
Well I never did that, but from the ListView reference it seems pretty clear that set setSelectionFromTop is what you are searching for.
See also how-to-autoscroll-a-list-view-in-android