android GridView, ListView and WebView in ScrollView - java

I'm implementing mail application for Android. I need to display mail content in ScrollView. The problem is I also need to display attachment as image backed GridView or ListView. Since it is not recommended to put aScrollable layout in ScrollView, how to organize my layout to have adapter based views inside ScrollView?

how to organize my layout to have adapter based views inside ScrollView?
You don't.
I need to display mail content in ScrollView.
Why? Why not display it in a non-selectable first row of the ListView? That way, it and the rest of the list scroll in unison. Remember that an Adapter can provide different row types, with different layouts, for different rows (via getViewTypeCount() and getItemViewType()). So you can have the first row be the message, with the rest of the rows being attachments and such.
Or, make the mail content scrollable in its own ScrollView, but have the attachments shown separately.

Related

How do I add a custom view to a layout programatically Android Studio

I want to implement a custom view into a LinearLayout that's inside of a ScrollLayout, but I don't know how many views I'll implement into the LinearLayout. What I want is like a scrolling box of interactive cards. How can I do this?
What I want is like a scrolling box of interactive cards.
Use RecyclerView instead of LinearLayout.

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.

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

How to disable scrolling for ListView on Android?

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)).

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