How to disable scrolling for ListView on Android? - java

I have the following question: I have a difficult layout that contain ListView. I need disable scrolling ability for ListView, because it's container (root Layout) have had ScrollView already, and I don't need a scrolls for ListView. I disable scrolls by android:scrollbars="none", but abilitity for scrolling would stay. I need that if ListView has 10 items that all items will be shown. How can I do it?

Can't you just use a LinearLayout with 10 elements instead of the ListView? It is not a good idea to have a ScrollView in another ScrollView.

Why do you still use the ListView? Create your own Layout for an item and load it several times (LayoutInflater, .addView(listItem)).

Related

How to add two Fragments with RecyclerView in a single layout and Scroll them?

I have a layout with two fragments. Both fragments have a Recyclerview. I want, When I scroll any of a recyclerView Then another recyclerView also scrolled automatically. How can I do this?
If you don't see each fragment at the same time, you could get the position of the viewable RecyclerView when you change views, then set the other RecyclerView to the same position.

how to show selection of the lst item in recycler view in android?

I have implemented the recycler view in navigation drawer in android.This is working fine.I am able to switch between item by clicking on recycler view item.
but i am not able to change the background color for the selected item.please suggest me how to imeplement it.I have tried this so far.
1.Background Selector in RecyclerView Item
Tried to make recycler view clickable,focusable but didn't work
2.http://innodroid.com/blog/post/tracking-selected-item-in-recyclerview
implemented but didn't understand where to write the code for changing background
Please help me out.
What you really need to understand with RecyclerView is that it's not the same control as a Listview with a funky adapter.
RecyclerView does not exhibit many of the ListView's functionalities and whilst it's understandable to compare it to a ListView or a GridView (or event a StaggeredGridView), it shouldn't be confused with them.
With RecyclerView, the responsibilities of handling the "background change" selector relies on the underlying control that the RecyclerView is holding. It's also the same with onClick and many other perks you get for free in a ListView.
Why it is better (or worse) to use a RecyclerView to a ListView is a different matter that I won't go into but to fix your problem, in order to set a background selector on your RecyclerView, add this to the layout that you're inflating in your ViewHolder (i.e. the actual layout that's being used inside the RecyclerView, similar to your "list row item" that you would inflate inside an ArrayAdapter if it were a ListView):
android:clickable="true"
android:background="?android:selectableItemBackground"
Which should set the background appropriately.
Recycler view are recommend when you have very large items & wants to have a custom UI. If you want to display only few items the would recommend to use List View.

Android - Custom ListView disable scrolling

I have a custom ListView which checks for a value in its adapter, and if its false it should disable scrolling. The reason I need to do this is because inside the listview are rows of horizontal listviews (using this implementation: https://github.com/dinocore1/DevsmartLib-Android) and if you scroll slightly up or down whilst scrolling on of these horizontal views, they stop scrolling and the listview instead scrolls.
The issue with this code is that it doesn't always seem to prevent the listview from scrolling, and it also doesn't pass the action through to the child (horizontal listview) like I believe it should (passing false).
Does anyone have any idea how I can get it to stop scrolling and still pass the movement action through to the child? Any help would be appreciated.
Thanks.

Using a ListView to lay out a list of checkboxes and text

I need to create a layout with a list of checkboxes on the left and text on the right. However, I need them to be laid out in a very specific way. I've searched for such a layout in many places, but no success (the closest I got to what I want was this.
This is the layout I need for my list
Can I achieve this with a ListView?
You can do it using ListView easily.
You should create your own Adapter and override your getView there
and return a RelativeLayout with your components inside e.g. a Button and a TextView
and set this adapter into your ListView.
Cheers
Create your own layout for each item in ListView and ListAdapter for your ListView
Check this link http://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html
Hope this helps you

Android - Dynamically add items to ListView using existing XML layouts?

I have a ListView that I want to dynamically add items to. For the items, I want to use a specific layout that I have defined in XML. How do I go about adding the items to it and have each item use the specific XML layout?
Do I have to create an adapter and jump through all those hoops? There is only a handful of items that I need to display. Each item has a few text views that need to be populated as well as an image that needs to be displayed.
If I go with the Adapter route, I need to basically creating a custom object/class that contains the text for each textview as well as the URL of the image I'm downloading. Seems like way overkill for just displaying a handful of listview items.
Isn't there someway I can just iterate through my items, inflate a view for each and add them to the listview?
you want to use a ScrollView for your purpose. works just like a listview, except the rule is a ScrollView should only have one child layout (that layout would be containing all the items you want to put inside). inflate a layout, then addView(). rinse repeat.
Unfortunately you do have to create an adapter. SimpleAdapter is about as easy as it gets. Here's a nice example that'll have you up and running in a few mins:
http://ykyuen.wordpress.com/2010/01/03/android-simple-listview-using-simpleadapter/
Either you can create an adapter which is really not all that complicated, or you can use a ScrollView with a LinearLayout inside and inflate yourself. Either option is reasonable, depending on your requirements, but inflating yourself and adding the views to the ListView manually isn't one of them. By the description you give, it sounds like you might just want to go the LinearLayout route.
Put a ScrollView with a LinearLayout inside in your main layout XML.
For each child:
Inflate the view for the child item and populate the fields accordingly.
Add the child view to the LinearLayout using addView.

Categories