How to Add fraction to a ListView? - android

I added a ListView and a Button to a layout.
What I want to do is, when I click the button, the ListView should scroll to a specified item such as the 10th to the top. But I don't want it to scroll too fast like flipping a page.
How can I do this? Can I add a fraction to a ListView? If so, how can this be archived?

i haven't try it but you can use "setSmoothScrollingEnabled(boolean smoothScrollingEnabled)" method of listview.
i think this will help you.

Related

ListView with animated images (animation on click on row) ; Android

I've already coded a ListView with images. But I'd like to add animations to it.
What I exactly want is I want to have two images in a row but only one visible. When I touch on it, the second should appear and the first should disappear.
I know how to make such an animation but not with a ListView.
Does anyone know that?
I think you are looking for somethink like This.
You can take custome listview with images and according to handle the animation on row click.

Adding a new item in a horizontal ListView when over scrolled to the right: Android

I have a Horizontal ScrollView that shows a number of items. I want to show an extra item only when the user over-scrolls to the right.
Then when the user scrolls back to the left this extra item should disappear. The View should normally scroll only in the first item and only on explicitly doing an over-scroll the extra item should be visible.
I am not able to figure out how to do this. Could someone please provide pointers on how to achieve this behaviour.
Thanks
Sunny.
The easiest way I would do it is define that extra item in the scrollview, but set it's visibility. You can do it in code. Here's a snippet.
yourobject.setVisibility(View.GONE);
yourobject.setVisibility(View.VISIBLE);

how to scroll to a particular screen location without actually scrolling

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

Changing Button position to top when clicked

I have a linear layout with about 20 buttons. I want to be able to change the button's position to the top of the screen when clicked. for example. the user clicks button # 7 i want the layout to scroll automatically so button #7 is on the top position of the screen.
please help out with some code
Thanks for Viewing
Place your LinearLayout in a ScrollView
Grab a reference to your ScrollView then in the onClick of the buttons use
http://developer.android.com/reference/android/widget/ScrollView.html#smoothScrollTo(int, int)
to scroll to the desired location.
You can achive your goal as JBirdVegas said or you can do one quick thing is. . .
Make ListView with Button on every index
Now onItemClickListener of the listview put below code and pass pressed index.
setSelection(index)
e.g.
you can use `setSelection(index)` so the display will jump to the index you want
Hope you will get the point.
Enjoy Coding. :)

Memory efficient list for android

I have a list of about 100 items. In each list item I need a framelayout with 2 relative layouts. When a button called "Flip" is clicked then one relative layout will flip out and the other relative layout will flip in. And each item has full width of the screen. So, I need to show the item in a horizontal scroll view. Now, I want to keep at most 3 items every moment. When user scrolls to the first item then we have to update the 3 items. The first item will be the 2nd item. And we have to add another item at the front. In this way we have to update the items when user scrolls to the last item. I have tried many ways. I have used Gallery for the horizontal scroll view. And used the onItemSelected method. But, if I scroll the Gallery fast then it crashes. So, please someone help me to implement the 3 items idea.
It sounds like you need a ListView. Is there a reason you are trying to reinvent it?
Also don't you mean a vertical scroll view? Why are using a horizontal?

Categories

Resources