I really stuck in a simple operation :-/
I have a number of section to swipe left / right as an Adapter / ViewPager, number of pages are defined dynamically during run-time.
There is button in the page which caption I would like to change during run time.
Of' cause Android is creating several pages in once to cash them and speed up scrolling. This leads to the problem that if I just look for a button using findViewById and change the caption, this change will be applied for the next screen, and not for the current visible one.
I can get the number of currently displayed ViewPager by .getCurrentItem but I cannot understand how I can address the very this button which is currently on screen.
Would be happy for any advice!
p.s. Sorry that I do not attach the code, it's quite long.
Change the text in an OnPageChangeListener with addOnPageChangeListener.
Related
I'm a beginner with short knowledge of programming, I've just started learning android development. I'm making an app and at one of the pages I have to make a certain kind of design that I cannot figure out how to or can't even find them in the internet. Basically, as you can see in the images below, next to the first textview, there's a little arrow. Whenever the user clicks on that arrow, two edittexts should appear below that texview just like in the second image and kind of drag the rest of the textviews down. I'd be really grateful if you guys could help me do this or at least provide me with some information on where to search this kind of problem solution. Thanks.
Just create your desired layout in xml with 2 edittext below each textview. But make sure You take these 2 edittexts in a single container. Lets say LinearLayout.
Then you would be easily able to show/hide these lineralayout based on the TextView click.
Or If You are using recyclerView, then it would be more easy. In this case, You have to show the 2 edittexts for currently clicked item only and will need to hide for all others
I need to make a layout similar to that Image.
I wish it were shown all the registered images and their attributes and a button to add the user would select an image and define the attributes of it. I do not want a complete example that ordered but at least one direction than I use to do the layout. By my research I should perhaps use a swipe view. Has anyone seen something similar?
Thank you
You can use ViewPager to display cards like in top part.
ViewPager with previous and next page boundaries
And use a ListView or RecyclerView to show the bottom part. https://code.tutsplus.com/tutorials/getting-started-with-recyclerview-and-cardview-on-android--cms-23465
I have created an Android app that allows people to select products and to then purchase them. My Product Selection screen uses a ViewPager to allow swiping the screen to display different groups of products. The ViewPager area uses a GridView to display the items.
Some of the items have a large name and therefore is not fully shown so I have added a Marquee feature to the text so that the name of the item scrolls which allows the name to be read fully. In general this feature works fine and the text scrolls as expected.
My issue occurs when swiping the screen; pages 1 & 2 work correctly and the text scrolls as expected but when swiping to other pages the text does not scroll. If a page contains lots of items, I can scroll the page up/down which then seems to trigger some sort of refresh on the GridView and the text then begins to scroll correctly.
I'm unsure why the marquee works for the 1st 2 pages and not the others (unless I scroll up/down to get the grid to refresh); the only thing that I can see is that my Fragments onCreateView() method is called twice upon initialization which seems to load the 1st 2 pages into memory. I've done a search on the Internet and this seems to be a normal process so is unlikely to be my issue.
I was wondering if there was a way to load all pages into memory (instead of just the 1st 2) or a way to force the GridView to refresh upon loading?
Any other suggestions would be great and I will give them a try.
Thanks...
I have a scrollview inside which I have 5 imageviews say IMV1,IMV2...IMV5 . Now on scrolling,one by one all imageviews are shown in device screen. Now I have a drawer with 5 buttons say 1,2 ..5.
Now take us a scenario,
Currently I am on first imageview. Now when I click on button 5 in the drawer.
I need IMV5 to show on the screen without scrolling.It can be obtained
through smoothScrollBy/scrollTo to y equal to 5*screenHeight. But here it
scrolls through all intermediate imageviews.
Please note,I don't wish to affect scroll feature.For above example,
After I reach IMV5,when I scroll up,it should scroll to IMV4 and so on.
Is there any way to obtain it .Please suggest.
Thanks In Advance.
P.S. If you need some more clarification,please let me know.
You can achieve this easily using a ListView instead of ScrollView.
What you can do is:-
Add all the imageviews to a ListView.
This will fulfill your scrolling requirement, as ListView automatically handles scrolling if its content's size is grater than the screen size.
Now use the listView.setSelection(position) on click of the buttons.
It will scroll to the selected imageview without giving the scrolling effect
Hope this helps.
It can be achieved through ScrollView too.. All you need to do is get the View at that position. Then call requestFocus() on the obtained view.
For example:- If you press Button 5, then IMV5.requestFocus() will do it for you
just wondering if anyone else has a better suggestion that what I'm coming up with.
The issue is to do with a TabLayout, 5 Tabs all using a single Activity. Each Tab layout contains quite a few fields so the main parent on each tab is a ScrollView.
What I currently have is a 'Save' & 'Cancel' button sitting outside the scrollviews so theyre always visible and there for the user regardless which tab they're on. The problem is that since I'm using Tabs and always have these buttons visible when they are editing and the IME is displayed, they'res barely any of the form visible.
So I think the best thing for me to do is to probably show the buttons at the end of each scrollview. What I don't like about this is as I have 5 tabs, it will mean I have to declare 5 sets of the buttons, and of course define them and bind them in the Activity.. which seems rather messy and inefficient.
So if anyone has any better ideas I sure would love to hear them :-)
Thanks
Rgds,
Dave
Some of the options you got is
Try to put a title bar, and move the save and cancel buttons there (Small image buttons).
Save can be moved to the menu too (not recommended).
Auto Save functionality can also help, depends on how useful is it to you.
Try to use custom images for tabs, and make it take less space.
else, remove the save and cancel buttons, after the user makes any modifications, and presses back, prompt him to save the unsaved changes.
You could make it that when you're in tab X, the tab button for tab X now becomes X(save), so if they click again on the tab button in the same tab, it saves. That saves you five buttons, potentially...
Define programmatically the buttons inside a LinearLayout and add them to each ScrollView with addView. The code of the buttons should check in what tab are we at that moment, and act accordingly.
Then you'll have the same two buttons arranged in the same way in all your ScrollViews.
Or, if you dislike doing it programmatically, do a layout for the buttons and use View.inflate of that layout, and add them via addView to the ScrollView.