How generate layout dynamically from mysql? - android

Is it possible to create a layout for an application on android from fields in a database?
I have a table in the database that contains questions and I want to generate a "form" or "layout" depending on the data that is in that table.
For example, I have question one:
as we see in the table I have the column "tipo_pregunta" which is what it will say if it is an input, checkbox, textarea, etc.
I wanted to know if it is possible or if you know some guide from which I can learn.

Yes. Of course, you can generate layout dynamically.
Create layout(LinearLayout, RelativeLayout etc) object.
Iterate database result
Create a view on checking your "tipo_pregunta" value. like(TextView, Checkbox, RadioButton etc)
Add this created view in your layout object - layoutObj.add(viewObj);
Repeat steps 3 & 4 till your database result count.

Related

Creating a Dynamic Table?

I am learning android development ,I want to create dynamic table rows .I don't know how to create .I want to create two table .One should static and Another should be dynamic .
I referred in internet and i saw table layout , recycler view and I don't know which is best way to do it.Please someone guid me.
I want to create a tables like this
I have tried like this only
You cannot simply create table and rows as simple as in webpages. you have to use TableLayout,TableRow and textview(for rendering text inside of it).
create no of textviews as cell and add it to TableRow(android layout) then add the tablerow and add it to TableLayout and then add tablelayout to root layout. On dynamic insertation invalidate the view to see changes

How to create table with runtime data addition - Android

I want to create a table in my android application, in which the data will be added on the run time i.e. no. of columns and rows would be decided on the base of user input and user can later add more columns or rows in the Table.
So, using Table Layout of Android is not solving my purpose so far. And I created the table using Linear Layouts under other linear layout, but as I add any row or column I have to create the whole view again which is making the application very slow. So, what can be other approaches or how can I improve the functionality of my application.
Thanks in Adavance.

android gridview or listview

I'm trying to develop a 3 column gridview and I need advices.
2 columns data coming from database and 3rd column is a delete button.
Data is stored in sqlite and columns like following;
1-Name: name of the product(string)
2-Type(Picture): type picture of the product, there are 10 pictures(type1.gif,type2.gif,...type10.gif)
3-Delete: It is a button or imagebutton which will delete the data from sqlite db.
Can you give a sample project link or tell me which one is better for performance and less code, gridview or listview?
As a suggestion,
you can create a list view, there you need to create a custom layout for the each row. This custom layout consist with textview (product name) , imageview (for the image) and a button. Once you click a certain button , you can get the product name/id from the respective model and delete the corresponding row from the database.
Use view holder patterns for this, and use lazy loader or similar technique to load the rows into the list (if total rows count is much larger).
This would be a the one of easy/efficient way to do this and you can easily find the code from google.

How to create layouts dynamically with each layout having unique functionality

I have 2 layout first one takes input and based on query show give output as shown in pic2.
However I am not able to introduce these layouts dynamically.
Each dynamic layout must have a unique id so that when "BOOK" is clicked specific ticket is booked.
http://i.stack.imgur.com/ez4DP.png
You should make the second layout not dynamic, but as a usual ListActivity of vertical LinearLayouts. And fill the ListActivity from the DB query.
The functionality you need is not unique at all, it only takes different DB table rows as a parameter. It is standard.

How to create a table above other list

I want to create a UI as shown in the below link:
http://i53.tinypic.com/sxksx5.jpg
According to me there can be the following approaches to do it.
There are two tables in this image. The above table should be made in the following way:
One row with two textview in one xml file. Now Inflate this UI using LayoutInflater. Draw It using a loop and set the text according to requirement.
The below table should be made in the following way:
How to make a dynamic table layout using XML
see the above link where It is advised that the 2nd table should be made using the listview.
Now I am confused that this can be made using gridvew, tablelayout, listview. Which one I should prefer and why? In my previous projects I have made this kind of UI almost in the coding. But I believe that a little change in the UI will require lot of change in the code. So I want to make the current UI using the xml. But dont know what approach would be best.
I'd suggest using a ListView. Subclass it and overload the getItem() method to render each column of the table row. You can then easily bind the listview to your data sources. you'll need to create an XML layout resource to describe a row of the table.
To show one table above another, put the listviews inside a RelativeLayout and specify attributes to position them relative to each other.
http://developer.android.com/reference/android/widget/ListView.html
http://developer.android.com/resources/tutorials/views/hello-relativelayout.html

Categories

Resources