In my application I am getting data from server and showing it using a table layout some times I am getting a data of atleast 20 to 30 rows but I want to show 4 rows at a time and then I want to show another 4 etc.
For this I want to know how can we use paging (Previous/Next) in Android if it's not possible with tablelayout can any one suggest which field can give that facility I aleady tried with GridView also but no luck
You can try this way ...
Store parsed data in List(or whatever) and create a method say createRows() which takes list as its argument and using list create rows.
So from your main list (parsed data list) create a sublist of size 4 and pass it to method. So initially it will create table with 4 row (as your requirement).
And on your next button first remove table's current rows using removeAllViews() method and then extract another sublist containing next 4 data to be shown & again pass it to createRows() method.So now it will create table with new data.
Same thing can be applied to previous button.
you can do it with fragments, there will be two fragments one will contain buttons(prev/next) or other fixed position data. and the other fragment will dynamically load data on request of button if you can program it.
Related
I want to create a dashboard wherein I want to populate some data in a GridView in android. For example,
Activity - GridView in which there are two columns.
Each grid is Header Text and Result Text.
Now I want to update only Result Text with time as I am fetching it from database and updating the values in real time.
Keeping my Header and whole view intact.
Can anyone suggest any quick way to do so...??
You only need to update the underlying data of the adapter and call notifyDataSetChanged() so the adapter knows the data was changed.
I get data from my server returned as an array of objects. Each object is itself an array of strings that describe the object.
For example let's use cars as the object. In this case, the array of strings are descriptors like 'year built', 'horsepower', 'automatic or manual', 'color', etc etc.
What I'd like to do is display only 1 car at a time for the user. The user can choose whether he likes or dislikes the car. Either way, a choice is final, and the next car will show up. Also, the user should not be able to go back to the previous car (not with a swipe or a clicking of aback button). In other words, he can never see his choice on the previous car again.
If I make a call to my server on every single 'like/dislike', this will be a very slow app. If I inflate a bunch of data into many views that are out of sight, it will also be a very slow app.
Most Array Adapter examples I see online illustrate how to show data bi-directionally. They are viewpagers or listviews that you can swipe left (or up) to view data that has been previously already viewed. This is not what I'm looking for.
Is there a proper way to implement what I'm trying to do? Any help will be appreciated as I'm just hoping to get some direction and can implement on my own. So far I'm thinking about possibly a viewpager that deletes items as you view them, but I have a feeling this will be really hard to manage the position of the views...
Use an array to hold the data you get from the server. You can request that the server send you 10 or 25 or 50 at a time.
Since you only want to show the user 1 at a time, and he can't scroll or swipe through the list, you only need a single set of views (enough to show all attributes of a single entry). You don't need an array adpater for this. Whenever you step from one entry to the next you just need to adjust the index into your array and then copy all the attributes of the new item into the individual views with setText() or setImageBitmap() or whatever.
im facing a problem in my project. What im trying to do is,
i need to parse a json reponse to a listview.
While clicking the row i will get some id , and now i need to call another webservice using that id and it should show another list .Suppose i clicked the First row ,ie Board "A". Then the next Listview should be the sublist of A . It might look like the following
A1,A2 etc may or maynot have submenus.
I can get the id of from the clicked row . And if the list is empty means no more submenus.
I dont know how to design this system? Does any one have any idea? Thanks in advance
PS: I will have to make different webservice call to get each submenu that depends on the ID im passing from the listview row click
A few ideas to get you started:
Instead of using ListView, take a look at GridView. ListView does not support more than one column (you have to support that manually) and GridView was introduced for this purpose.
Let's assume your initial list is shown in its own activity. This means you have an activity which queries the webservice on its onCreate() and then displays the results in the ListView/GridView when they are returned asynchronously from the webservice.
It will be convenient to hold the submenu in its own activity. This means you should create another activity for the submenu (maybe it can share code with the first one or even be derived from it to reduce code duplication). This activity will receive in its Intent an argument (take a look at Intent.putExtra and Intent.getExtra) which tells it which row was clicked (it should usually contain the String filter you are about to pass to the webservice). Once this activity is created, in its onCreate it should query the webservice much like the first activity and show its results in its own ListView/GridView.
To connect the two activities you'll need to catch the on click event in the first activity, figure out which row was clicked, and then create an Intent to show the 2nd activity, pass the extra and show it.
This approach will let the user dismiss the 2nd activity using the back key once they're finished with it. Once it's dismissed, the user will be returned to the 1st activity where they can click on a different row.
Following on from this question:
ideal database field for calling data to
I have realised that I might be able to simplify my need for information to be brought to the screen by using a Dialog or a Custom Dialog, and by one of these methods I may call the whole finished page from a database instead of using static strings into the layout filling in specific fields with data like I am currently.
There could be a few hundred items or pieces of data to be called up in my App So am I correct with this assumption or do I need a specific other method to acheive this?
I am looking to call a custom dailog from a database so I can call a whole page of information complete but am unsure of limitations on this data wise or even if my sqlite database manager is even good enough for this task, each page will be called up "complete" where as before I was trying to have a template with the unchanging data (coke pepsi etc.)already included and appearing on every "result" page and then blank fields populated with data retrieved from a sqlite database (Litres size etc...) I am unsure which path to take : either make the page complete including all data like an image Or do I stick with my original plan to have a template screen with unchanging fields already in place and the changing information to be populated as needed from a Sqlite Database? hope this makes sense sorry if I was too vague with my question originally Im still learning.
Your question is vague but I'll risk an answer:
If you want to make a dialog like the image you posted on your previous question then this is the way to do it:
Create a custom dialog that will have as content a LinearLayout(with 3 TextViews representing the header labels in your image: COMPONENT, TYPE and AMOUNT, this will be somewhat identical to the list row layout below) + a ListView where the actual data will be shown.
Create a layout file for your ListView row to use(like the LinearLayout above will contain 3 TextViews for the drink name, type number and amount number).
When the dialog needs to be shown just get from the database all the drinks names, types and amounts and bind it to the ListView with one of the adapters based on a Cursor(like a SimpleCursorAdapter)
Getting the values from the database and binding them to many TextViews is not recommended(If you have many(I saw few hundred items or pieces of data)), also your dialog could be called a lot of times by the user in a short period of time and you don't want to do this binding each time for many views.
either make the page complete including all data like an image
Please don't do this!
With the application i am working on i came with the following problem. I have a listview that should display data from a data base table. There are two scenarios that could happen:
Scenario one - the database table is filling dynamically and the listview also should dynamically display table's information e.g to grow depending on table size.
Scenario two - the table has been already filled and the listview has to just display the content
So the problem is how to accomplish this behavior using ListView and ListAdapter.
So far i have solution for each scenario but no for the two together.
Scenario one - Use AsyncTask and ArrayAdapter. In doInBackGround query the db periodically and pass the result to onProgressUpdate, than just fill the ArrayAdapter with the newly added values. But when came scenario two i query all the table than copy all values to the ArrayAdapter in one step which is pretty slow.
Scenario two - Query the db again the just use CursorAdapter. But in this case i can't update the ListView dynamically using CursorAdapter.
So any ideas how to implement this using one adapter, or just should i use ArrayAdapter and CursorAdapter depending on the case ?
Scenario one - the database table is
filling dynamically and the listview
also should dynamically display
table's information e.g to grow
depending on table size.
Try:
Scenario 1a: Whoever is getting the data not only puts it in the database, but tells the activity "here's some new data to display".
Databases are great data stores but are lousy pipes. Your "Scenario one" tries to use the database as a pipe -- instead, pipe around it.
Now, if the case is that you have both in-the-database data and new data coming in, you'll need to stitch those datasets together. You can use my MergeAdapter for it: give it two ListAdapters, one representing your existing data (perhaps a CursorAdapter) and one representing the new data (perhaps an ArrayAdapter). It will render them as a combined entity.