I'm currently a bit overstrained how to realize the following problem.
I want to realize a product overview as the figure shows.
In C# I would add a panel and add objects of one product (checkbox, textview, imageview) with a fixed position specification. And just group it for the others.
But how can I realize this (optimal) under Android Studio?
You can use a ListView with custom row layouts.
Your custom row layout can be a RelativeLayout, containing a CheckBox, some TextViews and an ImageView. It will be reused for every row by the ListView adapter. If you need the checkbox to indicate which rows the user selected (common in Windows UIs), consider implementing Checkable list views.
Related
If you are creating a very dynamic list, say, where every row can have a different set of input types plus optional buttons, and the list length is based on another dynamic value, is it better to do this in a list adapter or creating a custom view in a scroll window?
After struggling with list adapters for quite a while now something finally occurred to me- this seems dumb. It seems like I am going through a lot of work keeping track of what spinner is set to what value, which row was clicked and so forth.
For example, say you are showing something like a contacts screen with various details that can be entered about a contact. Some rows will have text inputs (name, address etc), some will have spinners (ie. state, group), some will have checkboxes (like 'favorite' or something). Also, there is an 'add' button that allows you to add another field to edit. Is it worth making this in a list adapter or is it better to populate a custom view, and if the "add" button is clicked, we re-create the custom view, adding a view of the type they want to add?
I hope this is clear.
ListViews (and List Adapters) are meant for data that is to be displayed in mainly similar views. For your example, it is much easier and more natural to have a predefined layout file with the screen and use view visibility so select which views are to be shown. If you need to add views to the screen you can do this dynamically by using findViewById on the layout and then using it's addView method.
Let me know if you need more clarification or sample code...
I implemented alphabetical section headers in my ListView by adding an additional TextView element in my ListView row layout and using this additional TextView element as the header by toggling it's setVisibility property when necessary in my custom CursorAdapter. So my row layout hierarchy consists of 2 TextView's inside a vertical LinearLayout.
I want the section headers to be independent of the row element it's contained in.
Originally, clicking on the header would perform the action of the row element it's contained in, so for example if my list consisted of the elements 'Apple' 'Apricot' and 'Avocado', clicking on the header, which is labeled as 'A' would perform whatever action of the row it's attached to, which in this example would be 'Apple'. I managed to prevent this from happening by setting the TextView representing the header as clickable.
However, I am still stuck with an annoying visual effect where when I click on 'Apple', the highlighting showing my selection on click highlights the entire row, so both TextView's are highlighted. Here is an example showing what I mean. In this example, when I click 'Daft Punk', the attached header 'D' is also highlighted. Is there anyway to set it so that only the second TextView is highlighted?
That isn't supported in a non-hacky way. If you want to properly implement a listview with sections, there's a plethora of examples using the supported multiple view types strategy.
Here are two questions for implementations and libs that do what you want:
Android listview groups
Creating categories in a ListView?
A tutorial to roll your own:
http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/
If you do want to go the hacky route, in the comments for this post, he mentions intercepting touch by exploiting the focus/click event behavior bug.
Cyril Mottier
I have the following prototype:
What is the way to list views in a scroll-able way in a screen?
What I have already tried:
I tried to create a class and extends the LinearLayout class and dynamically adds my Views (the compound controls class is my view also extends LinearLayout) to the main LinearLayout. So I got a list of my views which is scroll-able.
I'm not sure what you mean, but looking at what you have tried, what's wrong with using a ListView? As the name implies, it should do exactly what you want:
What is the way to list views in a scroll-able way in a screen?
Here is a quote from the android documentation of a ListView
ListView is a view group that displays a list of scrollable items. The
list items are automatically inserted to the list using an Adapter
that pulls content from a source such as an array or database query
and converts each item result into a view that's placed into the list.
You should be able to add a ListView directly as a sub-view under your LinearLayout.
your questions seems like hard to understand.
did you mean how to set the whole page(activity) into a listview?
listviews are scrollable in default (of course, you can see it if the list is long enough and you can set the whole activity as a list).. you can customize it also by using templates (xml)
and extending ArrayAdapter of your type (let's say ArrayAdapter<UpcomingEvents>) and supply data from db...
is this what you mean?
This layout is a shelf with 3 books each row.
I current come up with gridview for displaying the books and manually add up the shelf bar. The problem occurs when there are more than 9 books and the layout is broken when scrolling the grid.
Could anyone suggest me another better way to deal with this layout. Thanks
I think you should set the background in each element (one shelf) instead of the setting the Grid container background (three shelf) ....
it's looking difficult in your case because it would has three images in a row ..So you need to try some this switch(position%3) in getView of adapter to set three different image
or
Use the ListView and Re-set the data in Array List so that each element has three books and you can make all three images clickable of that row and can make list row unclickable and unfocusable
We are developing an Android project. In that project we need to create a list view with multiple objects.
Inside each list view item we need to show Name, Mobile, Checkbox1 and Checkbox2
We tried with various options and we are clue less how to get this done.
You can create an .xml file, which contains a Layout (LinearLayout, RelativeLayout etc) and inside that layout put some Views like TextViews for the Name and Mobile and 2 CheckBox items for your checkboxes. I recommend this tutorial for more on ListView issues.
You need to define your own row layout and also your own ListAdapter implementation. The adapter needs to override getView to return your custom row view. There's a good example here that extends an ArrayAdapter. There's another example here that extends a CursorAdapter. Search the web for android custom listview row to get lots of other examples.