how to design a tableview in android app - android

I found the following design in market of my tablet. I want to design a layout as like the below tables containing a image, text and a button for my android app. how to do this

You can achieve simple table look, by setting different colors to rows and cloumns and set appropriate margins in that here is example. Here he sets only border but you can fill any color or drawable inside column.

For this solution, i would suggest you to design custom adapter to be displayed either in GridView or in multi column ListView.
But i think GridView would be best to implement the above functionality.
Now, to define a custom adapter, you just have to create a simple class and extends BaseAdapter, and then you have to override the getView() method inside this class. Now within the getView() method, you can inflate() the custom row layout file (which you define for one item , this item xml layout file represents every items inside the GridView).
Here is the simple example for implementing a simple GridView.
For the detailed exmmple of such gridview, refer this example: Android - GridView example

Related

Android: Creating custom view and adding it to layout dynamically

I want to create a custom view with some text and two buttons all on one line. I need to be able to add multiple (any number) of these views to an existing layout dynamically (needs to be able to scroll). I want to pass a custom object to the view and set the text and buttons. I need access to the button event handlers from the activity. I've looked a little into custom views but I'm still at a loss for how to do what I want. I'm used to .NET custom controls, and I'm looking for the same effect. Any help or example code would be greatly appreciated.
What you want is custom compound view. You should write you own class (usually extending one of the layouts) and whole behavior, inflate the layout the way you want etc.
More of it: http://developer.android.com/guide/topics/ui/custom-components.html
This one helped me a lot too: http://javatechig.com/android/creating-custom-and-compound-views-in-android-tutorial
If you use list activity or list fragment, you will automatically have the many features you have asked for. You only need to create a adapter class for your listview. You can define your layout for your row view(buttons, text etc..) Try to look at the examples on the web for cusom adapter and lists.

What to use other than listview?

Anyone knows how the center part is being listed? I tried using listview but it does not have a space large enough for the image
You need to customize the normal behavior of the ListView. The layout you see inside each row, is a separate layout file prepared, that contains some TextViews, ImageViews, and that layout file is inflated as a row of the ListView.
Check out this example: http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92
Very nicely explained how we can customize a ListView.
I think you would be able to use a scrollview then just add some views and layouts inside it.
If you create you own list adapter you can inflate all kinds of views inside a normal listview
extends ArrayAdapter<Object>
And overwrite the getView method
You can have look at PintrestListViewAdapter which is opensource
Check out the Implementation demo HERE

How to list Views (or Widgets) in one scrollable screen

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?

android: Is it possible to put multiple layouts in listview items

hi I want to use a listview (probably) is it possible to fill each entry with say two buttons two text areas, and have them laid out with realtive or linear layouts?
I have used a scroll view with layout inflator to achieve this at the moment, but I'm thinking listview would be better maybe?
yes you can. you need to use a custom list view for that. making an activity by adding a listview in it and then referencing another xml to that listview using an AAdapter so that every element of the listview has the layout of the second xml file. this tutorial should help you understand the idea.
Yes you can place any widgets for the particular List Item for your listview.
For defining that kind of ListView, you have to define a custom adapter, follow the below steps:
Define a one row file for the list item, say for example, RelativeLayout with 2-3 TextViews.
Define a class by extending BaseAdapter.
Inflate the XML and do display operations inside the getView() method of this class.
Set this adapter to the ListView.

Placing multiple objects inside a list view

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.

Categories

Resources