Android auto reduce data table - android

I am new to Android, and I have a table I made using:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/question_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:orientation="vertical"
android:layout_below="#+id/textView7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/linearLayout">
</TableLayout>
added rows to it and it perfectly shows the table. Now I want to implement a search box that reduce the result as I type, I am not sure how to do that. I tried searching, maybe I am missing the term to search. Can someone please add a link to it and/or tell me some technique, because re-populating the table everything someone types is like a bad thing to do.
PS: Data is sent from API as JSON, and I own the API.

Displaying large information in TableLayout is bad practice. You can use ListView. Because, every time when text changed in your search box, you need to clear all views in TableLayout, then you need to create rows that appropriate your search filter and then you need to add these rows to TableLayout again. Creating many views and drawing them on screen is hard process for Android and it can crash your app.

Related

Table Layout with dynamic amount of rows and dynamic content

Im pretty new to Android Development, so after like three days of trying different things with the XML Layout Design, i give up and hope for help from you guys.
What i want to achieve:
A table layout with with multiple rows, each filled with calculations im making in the background
The first three rows shall contain the input parameters, the following ~12 rows shall contain output parameters
rows 3 to 6 shall be rearrangeable, so to speak change name and shown values.
This is the concept, thats what one row should look like:
My way of trying things was:
Creating a TableRow for "Taupunkt" and "Td" and another one for three textfields and the +/- picture.
But how on earth am i supposed to insert the ">" arrows picture into the layout? Basically it should be centered between the rows.
I hope i did a clear explanation of my problem and hope that there is someone out there who can help me :)
PS.: App is going to support Android 4.0 and above
EDIT: As seen in the picture, how would i go about centering the plus/minus vertically to the textfields? Like, it should have the same space above and below it to the textfields
You can use ListView or RecyclerView as mentioned in comments.
For second question to make your view centrally aligned you can use android:gravity attribute in LinearLayout. Just made one same which is using center_vertical. Checkout -
<LinearLayout
android:id="#+id/btn_google"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/standard_padding"
android:background="#drawable/rectangle_round_red"
android:gravity="center_vertical"
android:minHeight="#dimen/standard_height"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_google" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Google"
android:textColor="#android:color/white"
android:textSize="#dimen/font_18" />
</LinearLayout>
This is how it looks

how to display table on android with enabled scrolling

I'm working on an application for android, where users can upload their csv files.
ofcourse csv files can have lots of rows and/or columns, so my problem is how to display all that data within android table.
i would like to know how to do that and enable scrolling in both horizontal and vertical direction, so the whole table can be viewed?
thanks in advance
If you want to use a table, just put it inside a ScrollView.
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TableLayout>
</ScrollView>
Anyway, I don't know if using a table is the best option. I think tables in Android should be deprecated already.

Displaying a TextView immediately after another

I am a first time developer for Android, so you can say I've been learning as I was developing. For most of my code that doesn't have to do with the XML layout, I had no problem patching my rookie mistakes. With that said, my rookie mistakes has caught up to me in regards to two TextViews when I initially designed them with the GUI interface designer (my major rookie mistake).
My display_city tv and display_today_date tv seem to have a symbiotic relationship with each other. Removal of either one would crash the app. They seem so dependent on each other that changing each other's positioning is impossible (at least from the myriad of things I have tried such as setting layout margins).
<TextView
android:id="#+id/display_city"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dip"
android:layout_above="#+id/display_today_date"
android:layout_below="#+id/get_data"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal" />
<TextView
android:id="#+id/display_today_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/display_pollen_type"/>
My question is - how do I simply position display_today_date immediately after my display_city? When I first started this Android app, I relied a lot on the GUI builder. That was my first rookie mistake, which resulted in this symbiotic relationship I explained.
Currently this is what my app looks like:
I have tried changing display_today_date's layout to android:layout_below="#+id/display_city. This results in a crash. I checked logcat, but it did not give me relevant information to the reason of the crash within the XML file.
P.S. get_data is my TextEdit box.
You already have the city to show above the date with the line android:layout_above="#+id/display_today_date". You can't have 2 views in a relative layout each reference the other, or it won't be able to figure out what to do. If you don't want to put the city above the date, delete that line then add the code to place it where you want.
You could use a LinearLayout with the orientation set to horizontal. That way there is no reference to another view. So if you delete one the other one won't cause the app to crash.

Android - How to make a vertically-scrollable list

I am new to Android development, and have tried researching my question but can not find a suitable answer.
What I am trying to do is create a list of items, like the numbers 0-9 for example, and display that as a list that the user can scroll up or down to select the desired number, starting at 0.
The best example that I can think of is the HTC Sense timer, linked below (can not post pictures as a new user):
Sense Timer:
What I currently have is a Spinner, but that's not exactly what I want. I want the user to simply swipe up/down to make their selection, not press a button to bring up a drop-down list to make their selection.
Is there a simple way to do this that I am missing, or is it a fairly complicated thing to do? I have not been able to find an example on my own.
Thanks
This is simply known as Wheel View in android. I am not much aware of its implementation, but here is a very good demo. Take a look at it.
http://android-devblog.blogspot.in/2010/05/wheel-ui-contol.html
This will get you started with it.
Here is another one,
http://android-devblog.blogspot.in/2011/01/android-wheel-update-custom-views-for.html
Try ScrollView, may this will work:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
//Your Components
</RelativeLayout>
</ScrollView>
You need to use a listview and an adapter for this. Its a very simple way to implement the vertical scrolling list of items. Please refer the code from the following link:
http://developer.android.com/resources/tutorials/views/hello-listview.html

How to make a sectionised ListView

I have been searching all day on how to make these sections in a ListView. Haven't found anything yet. I have been through many blogs and most of them talk about the approach CommonsWare takes (i.e. SectionAdapter) but the SectionAdapter.java is nowhere to be seen on his GitHub repo.
How can this be made? (i.e. the part marked A. I am not trying to make a Preferences list. Something more on the lines of a Contact List)
I struggled a lot on this. There are a number of ways to do this. The one I found simplest and which I recommend is using separator view in your list item layout (the one you inflate in get view) and change its visibility based on whether on not there should be a header. I use something like this:
<TextView
android:id="#+id/separator"
android:layout_width="fill_parent"
android:visibility="gone"
android:layout_height="wrap_content" />
I found this much simpler than the other adapter. I just kept track of where I wanted to have a separator using a variable and based on that I setVisibility(View.VISIBLE) in my getView().
Try putting this on the textview in the xml:
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:id="#+id/tv_separator"
android:visibility="gone"
/>
this will make it like preferences categories that looks much better..

Categories

Resources