Custom TextView and ListView versus a GridView suggestions - android

I have an application that is a task management application. The application uses tabs to separate tasks, calendar, and notes functionality. The primary view by the user is a Task view which is currently implemented as a List with a ListAdaptor class to put all the widgets together in a single row.
Each row contains the following items:
Spinner to allow use to select the priority for a task (i.e. A1, A2.. B1.. D4)
TextView to enter a description of the tasks
CheckBox for the user to indicate if the task is completed
TextView for an optional date field
Button to attach a note to the task
On a phone the above items take up too much room. For example, the spinner component takes up space to display the value as well as the drop down menu. Checkbox and button are also too big for the list view on a device like a phone.
Here are my questions:
Custom Spinner. What I really need in the application is a simple text field that shows the users priority for the task with the ability to click on the text and select from options similar to a spinner component. Should I extend a TextView component to do that or is it possible to modify the look of the Spinner to function like a spinner but display like a text field?
Shrinking components. Is it possible to shrink the default Android components like the spinner, checkbox, and button to better fit in a row with limited size? Do I have to extend components to do this or are their attributes that can do this easier?
Lastly, I have implemented this functionality using a ListView. Would it be easier to control the cells in each row using a GridView instead of a ListView? What are the benefits and disadvantages to using a GridView versus a ListView?
Thanks in advance for an advice on the above questions.
Brett

Why don't you add a click listener to your TextView and show for example a context menu with all your items when TextView is clicked.
You may limit the size of the components by setting their width/height to a desired value. Set text size, paddings and margins of the components to a minimum value as well. Note that components' background may also define paddings, so define your own background drawable with no paddings.
Not many differences. You will provide ListAdapter for both. I would say that GridView is likely used for galleries, ListView being used for tasks like your. ListView also gives you more control over its items.

Related

Which is the better method in Android for creating a dynamic list?

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

Custom controls/inflating an XML onto an Android layout?

I have a standard layout and i have to populate it at runtime with a number of controls/views i.e. TextView / EditText depending on the number of products that come back from a REST service.
Of course the control I wish to add to the layout at runtime needs to contain a number of views (textview, edittext) etc. I was thinking a custom control to bring all the controls I need I am unsure.
The other idea I had was to inflate and existing XML into my layout but I am unsure if this is possible or if it was or would I control the ID names - inserting more than 1 would cause duplicate id's?
I will try and explain in detail what I am trying to do, we can wrap it in a for loop for test which would count form 1 to 5 hence 5 controls would get populated on my layout.
The custom controls would have a TextView which describes the product. The Edit text where the user can enter freely the amount in numbers using the virtual keyboard and a spinner control to the right of the EditText which would allow the increasing of the EdtiText value.
So all pretty simple eh ? :-) but of could I class all these controls as 1 specific view and I need to a number of them on my layout hence if there were 5 products there would be 5 custom controls, each custom control contain controls i.e. TextView, EditText and Spinner.
How can I accomplish this?
The examples I have seen have been inheriting from VIEW but I need my VIEW (CUSTOM CONTROL) to be a container for a number of other controls and then later be able to dynamically add this new custom control onto my Activity Layout.
What about using a ListView with custom adapter...
check http://www.ezzylearning.com/tutorial.aspx?tid=1763429
http://www.framentos.com/en/android-tutorial/2012/07/16/listview-in-android-using-custom-listadapter-and-viewcache/
You may want to use a ListView with a custom Adapter, and update the adapter with the information from the service.

Custom UI object android

Im quite new to android development and in fact also Java. I have created an activity where I have several "rounded corner" transparable gradient-"buttons" that is made up of an absolutelayout, and two texfields.
Now I want these "buttons" to be added to my screen based on some values in a database. So the UI is dynamic. It must be fetched from DB. So it can be 10 "buttons" and it can be 1 "button".
How can I add these "buttons" dynamically Adding text from DB? and still have click-events etc. This is how the "buttons" are defined in XML: (I have removed some of the elements)
Hope someone out there understands the problem, and are able to help.
Button newButton = (Button) findViewById(R.id.new_button);
newButton.setText("Click me");
Get the values from database and create a loop. Instead of setting the text in xml, set the text programmatically in your activity class.
What's the reason you need so many buttons? And how do you want them to be located on the screen? Actually, it's a bad practice to create undefined amount of buttons. May be you just need a ListView with CursorAdapter attached. You will get the list of items, the text could be set from databse automatically by CursorAdapter, and you can make items to be "rounded corner" transparable gradient attaching this layout in adapter's getView(). And handling onItemClick() you will get the Button functionality.

Image in a custom List Android

I have created a custom adapter to display a list, there is an image that is displayed in each row ( the image is the same for all rows, except using an array i am assigning it different values depending on the position). An xml file defines the relative layout that i am using. My problem is that i can either get the entire row to be clickable or nothing at all, I only want this image to be clickable, instead of the entire row. How would i be able to do this ? i am new to android and am pretty much following different tutorials trying to create my list. Any help would be appreciated.
layout is like this :
TEXT:
[Image]
TEXT:
thats wat a row looks like...getting two texts from two different arrays and shows it, a third array is used to link to the image. I just want this image to be clickable instead of the entire row.
Thanks
Android's list component manages clicks per row. This makes it very difficult to achieve what you want to do. Two solutions come into mind:
1) If your list is never very long you could simply use linear layout and scroll view to build the list. This approach won't work if you fill in the list dynamically and you can't be sure that there won't be a very large number of rows as it would use too much memory in that case.
2) Other option is to use ListView but make your text components and images different view types in list ie. break you row into three.
That can be achieved overriding list adapter's getItemViewType(int)
http://developer.android.com/reference/android/widget/Adapter.html#getItemViewType(int)
In this approach you can make the image rows clickable but the text rows not.

How to implement custom view with variable fields?

I have a ListView that displays a set of notes, each with varying ammounts of data (i.e. some have a due date, others don't).
Currently, each view in the list is a RelativeLayout containing a TextView for each field, plus two Button and a CheckBox. I then simply hide the unused fields by setting visible false on each one.
This has worked well, but I'm about to add a lot more data fields to the notes and inflating that many unneeded views for each row will surely kill my app. I need a more dynamic solution.
I've decided the best way to go is to create a custom view. How can I implement/design my view so that it can display a variable number of text fields without creating/destroying textviews each time (which would be quite expensive and worse than my current situation), or maintaining a large pool of hidden textviews?
You can create a class that extends LinearLayout
and use addView to dynamically place your views.
Sounds like you might want to look into a view with a stub. The stubs will save space until they are inflated, so each row will be lighter until it is used on a heftier view. If you have a relatively low number of these larger views you might save a bit of overhead.

Categories

Resources