GithubHelp home page GithubHelp logo

ischwarz23 / sortabletableview Goto Github PK

View Code? Open in Web Editor NEW
1.1K 43.0 240.0 3.21 MB

An Android library containing a simple TableView and an advanced SortableTableView providing a lot of customisation possibilities to fit all needs.

License: Apache License 2.0

Java 100.00%
sortabletableview android-library tableview android android-ui material-design

sortabletableview's People

Contributors

ischwarz23 avatar ktanna avatar ooelectron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sortabletableview's Issues

View recycling

I've noticed that TableDataAdapter.getCellView isn't called with a converView that you can use to recycleviews.

I think this causes causes significant performance degradation, I notice this when scrolling very fast through a long list, which results in very jerky scrolling behavior.

Is there a reason why you do not reuse the convertView in TableDataAdapter.getView if not null, and do not pass the original cellView to the TableDataAdapter.getCellView (if it exists)?

Scroll-able along with other items, outside it's container

Hello,
Thank you for the swift reply to my question. I've opened it as a new issue as you advised.
I tried the syntax as you requested. It works well, though a small bit still bugs me. So I enclosed it in a scrollview but it still scrolls inside itself.

The structure of my layout file
`
ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<LinearLayout>  header views like instructions, etc </LinearLayout>

    <de.codecrafters.tableview.TableView
        xmlns:table="http://schemas.android.com/apk/res-auto"
        android:id="@+id/instTableView"
        android:orientation="vertical"
        android:layout_marginTop="10dip"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="@color/list_divider"
        android:dividerHeight="1dip"
        android:textSize="10sp"
        android:layout_marginBottom="50dp"
        android:background="@drawable/flat_border_set"
        android:gravity="center_horizontal"/>
//Long list of item views {table rows}

<LinearLayout> - footer views eg share buttons etc </LinearLayout>

</ScrollView`

As it is, when I scroll down the rows scroll within the table container. This becomes a challenge for smaller screens.

So, I'd like to have the whole page to scroll so that if a user scrolls down, the table view scrolls along with everything else. Am I doing it wrong?

Joe

Scrollbar not present

Hi,

Thanks for this library!

On my Nexus 6 running Android 5.1.1 and my Nexus 7 (2103) running 6.01, I'm not seeing a scrollbar in my tableview.

Do I need to do something different or is this a bug?

I/de.codecrafters.tableview.SortableTableView: Unable to sort column with index -1. Reason: no comparator set for this column.

The example application from the google play store does not exhibit this issue. However, following the instructions from the readme.md file, any time the orientation of the screen changes, the warning (from the title) appears in the debug log. I'm using 2.2.1 on android 6.0

This is the view

<de.codecrafters.tableview.SortableTableView
        xmlns:table="http://schemas.android.com/apk/res-auto"
        android:id="@+id/tableView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

This is the code in a fragment

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_history, container, false);
        SortableTableView<String[]> tableView = (SortableTableView<String[]>) v.findViewById(R.id.tableView);

        String[] header = {"Scan", "Hardware ID", "Timestamp", "blood"};
        tableView.setHeaderAdapter(new SimpleTableHeaderAdapter(getActivity(), header));


        tableView.setColumnCount(4);

        String[][] data = {{"no", "data", "yet", ":("}};
        tableView.setDataAdapter(new SimpleTableDataAdapter(getActivity(), data));
        tableView.setColumnComparator(0, (String[] lhs, String[] rhs)->Integer.parseInt(lhs[0]) - Integer.parseInt(rhs[0]));
        tableView.setColumnComparator(1, (String[] lhs, String[] rhs)->lhs[1].compareTo(rhs[1]));
        tableView.setColumnComparator(2, (String[] lhs, String[] rhs)->lhs[2].compareTo(rhs[2]));
        tableView.setColumnComparator(3, (String[] lhs, String[] rhs)->Integer.parseInt(lhs[3]) - Integer.parseInt(rhs[3]));
        return v;
    }

Interestingly enough, the first instance of this fragment getting created won't display that error/warning onto the log.

Divider for data and header row elements

Hello! Can you add methods like this?
setDataRowElementDividerHeight()
setDataRowElementDividerColor()
setHeaderRowElementDividerHeight()
setHeaderRowElementDividerColor()

Header shriking while creating several columns

First, i want to thank you for this amazing lib.

I have a problem while creating several columns, they are shrinking in size and the columns names stay like ("header here..."), i have tried to increase the setColumnWeight but with no success, i already added the horizontal scroll view like the other issues presented. Is there any way to increase the width of the columns ?

Sorting indicator not "activated" for default sorted column

Hello Ingo, Thank you for such a great contribution!

Can you please let me know how to "activate" the sorting indicator for the default sorted column? My goal is to clearly communicate to the user which column is sorted and in which direction. Once the user clicks on a particular column, the indicator is clearly activating but not before clicking.
thanks again!

tableview folder . newbie

Hi im newbie

It says

To use the this library in your project simply add the following dependency to your build.gradle file.

dependencies {
compile 'de.codecrafters.tableview:tableview:0.9.5'
}

It's clear that I should copy the tableview folder and add the dependencies on build.gradle. Where should I copy the tableview folder to?

Table grows when sorting within HorizontalScrollView

Hello Ingo,

I really enjoy using your SortableTableView for my app, it's a really great library. Unfortunately, there is one problem that I have with it: When I use a SortableTableView inside a HorizontalScrollView, then each time I tab a table header to sort the table, the table grows a bit wider. To recreate this you can use your sample project in your repository and just put the View into a HorizontalScrollView. The resulting main_activity.xml looks as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                xmlns:custom="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="de.codecrafters.tableviewexample.MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primary"
        custom:title="@string/title_activity_main"
        custom:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

    <android.widget.HorizontalScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <de.codecrafters.tableviewexample.SortableCarTableView
            android:id="@+id/tableView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/toolbar"
            custom:columnCount="4"
            custom:headerElevation="10"
            custom:headerColor="@color/primary" />

    </android.widget.HorizontalScrollView>

</RelativeLayout>

Is this a bug or is this intended behavior? If it is the latter, can you please tell me how I can prevent the table from growing?

Best Regards,
Luparion

Adding Header Text.

Hi ,

Im trying to add text to the header but failing.
How can it be done?

What i have tried,

TableView<String[]> tableView = (TableView<String[]>) getView().findViewById(R.id.view12);
tableView.setHeaderBackground(R.color.accent);
SimpleTableHeaderAdapter simpleTableHeaderAdapter = new SimpleTableHeaderAdapter(container,false, R.string.id, R.string.alarm, R.string.Add);
tableView.setHeaderAdapter(simpleTableHeaderAdapter);

Getting error while adding the dependency

Hi I am new to android. As you mentioned in your read me file. I added a dependency in build.gradle file. When I am trying to sync my gradle file I am getting the below error.

"Error:(27, 13) Failed to resolve: de.codecrafters.tableview:tableview:2.1.0"

Can you please help me understand as to how I can add dependency in my application. Is there any other step that needs to be done apart from putting an entry in the gradle file?

FloatingActionButton

I find i use the this and can't build the project when i had use FloatingActionButton

the Error show:
Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering

java.lang.RuntimeException: Unable to start activity ComponentInfo{beans.physicalfitness/beans.physicalfitness.MainActivity}: android.view.InflateException: Binary XML file line #26: Error inflating class android.support.design.widget.FloatingActionButton

thanks

Set column widths to wrap_content instead using weights

Is there an option to set column widths to wrap content instead using weights? It would be nice if it worked like a typical linear layout: wrap content for most of the columns and set weight to the one that should take the rest of available space.

Sort

Hello!
How to add many sort algorithm?

    private static class MySortStateViewProvider implements SortStateViewProvider {

        private static final int NO_IMAGE_RES = -1;

        @Override
        public int getSortStateViewResource(SortState state) {
            switch (state) {
                case SORTABLE:
                    return R.mipmap.ic_sortable;
                case SORTED_ASC:
                    return R.mipmap.ic_sorted_asc;
                case SORTED_DESC:
                    return R.mipmap.ic_sorted_desc;
                default:
                    return NO_IMAGE_RES;
            }
        }
    }

Need more sorting algorithm.
Exapmle:
| header |
| new |
| pending |
| done |
| pending |
| pending |
| done |
How to sort "first new" or "first done"? Use Comparator?

sortableTableView.setColumnComparator(0, new CarProducerComparator());

No! Comparator sort "-1, 0, 1".
And need more sorting button, or popup menu.
Sorry my bad english. =(

Kang

Hello, thanks for your great work, I have a problem when add many headers, and each header fully wraps the content, so maybe need to scroll horizontally, can you tell me how to solve this problems, thanks!

notifyDataSetChanged(); not working

Today I have tried using your library to show some data but after updating it I cannot refresh the data in the adapter, because the method adapter.notifyDataSetChanged(); doesn't seem to work? Did I make a mistake somewhere, should I post my code here or is this a known issue?

Findviewbyid return null

Hello,

When i try to get sortabletableview it return me Null, i'm using it in fragment.

materiauTableView = (SortableMateriauTableView) view.findViewById(R.id.tableView);

<com.diadecmobile.view.fragment.projectFragment.materiauxFragment.SortableMateriauTableView
        android:id="@+id/tableView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        custom:columnCount="8"
        custom:headerElevation="10"
        custom:headerColor="@color/theme_primary" />

How to colorize the divider?

Hello! Does library can colorize divider or make it transperent?
android:divider and .setDividerDrawable won't work at all
Thanks!

Provide my own view for sortable_header.xml

Hello,

I'd like to be able to provide my own view for for the SortableTableHeaderView. Instead of the the little widget, I'd like to overlay the header when it's sorted. Unfortunately there isn't a way to override or inject anything in SortableTable to do this.

Do you think it'd be a good idea to allow SortableTableView to inject a custom content provider to inflate the headerContainerLayout in SortableTableHeaderView.renderHeaderViews()? I think we can also change the LinearLayout to a ViewGroup.

I'm thinking something like:

final ViewGroup headerContainerLayout = (ViewGroup) mHeaderContentProvider(adapter, this);

Then providing the appropriate setters on SortableTable and SortableTableHeaderView.

The the default provider would just inflate the current R.layout.sortable_header.

Header doesn't appear

Hi,

There is an issue with the library when I want to use header. If I don't put any view above the SortableTableView, the header never appears. Some examples with your sample :

  • Remove the toolbar in activity_main.xml
  • Replace RelativeLayout by a LinearLayout

I think it's an issue because we don't need RelativeLayout everytime. The only workaround I found is using a fakeView above the TableView:

<View
    android:id="@+id/fakeView"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="?attr/colorPrimary"/>

<fr.fnac.connect.ui.component.SortableProductTableView
    android:id="@+id/comparison_table"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/fakeView"
    app:columnCount="4"
    app:headerColor="?attr/colorPrimary"
    app:headerElevation="10"/>

Julien

Crash on orientation change / restore instance state

There's some kind of bug introduced with the 0.9.6 version. When changing the orientation of the device, an unhandled exception is throw from the restore instance state code. It can be replicated using the demo app. Version 0.9.5 works correctly.

FATAL EXCEPTION: main
  Process: de.codecrafters.tableviewexample, PID: 20881
  java.lang.RuntimeException: Unable to start activity ComponentInfo{de.codecrafters.tableviewexample/de.codecrafters.tableviewexample.MainActivity}: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.AbsListView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/tableView. Make sure other views do not use the same id.
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
      at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4053)
      at android.app.ActivityThread.access$900(ActivityThread.java:156)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:211)
      at android.app.ActivityThread.main(ActivityThread.java:5373)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
   Caused by: java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.AbsListView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/tableView. Make sure other views do not use the same id.
      at android.view.View.onRestoreInstanceState(View.java:13847)
      at android.view.View.dispatchRestoreInstanceState(View.java:13823)
      at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2888)
      at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2894)
      at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2894)
      at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2894)
      at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:2894)
      at android.view.View.restoreHierarchyState(View.java:13801)
      at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2012)
      at android.app.Activity.onRestoreInstanceState(Activity.java:1023)
      at android.app.Activity.performRestoreInstanceState(Activity.java:978)
      at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1162)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2352)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442) 
      at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4053) 
      at android.app.ActivityThread.access$900(ActivityThread.java:156) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1357) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:211) 
      at android.app.ActivityThread.main(ActivityThread.java:5373) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:372) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815) 

isn't there a way to make it scrollable horizontally?

thanks for your great library,

I have a problem. in my situation I have tables with 10-50 columns, I really need to have a horizontal scroll for it and also making more width for each column. is there anyway to do that?

Using the Eclipse ADT?

Hello, I would like to use this library in Eclipse ADT but without success.
Xml layout can not inflate the component:

     <de.codecrafters.tableviewexample.SortableCarTableView
         android: id = "@ + id / tableView"
         android: layout_width = "match_parent"
         android: layout_height = "match_parent"
         android: layout_below = "@ id / toolbar"
         custom: tableView_columnCount = "4"
         custom: tableView_headerElevation = "10"
         custom: tableView_headerColor = "@ color / primary" />

giving an error that does not exist.

How to do this?

ScrollView for several SortableTableViews

Hello, i was trying to put several tables inside a ScrollView, for example:

<ScrollView ... <RelativeLayout ... <HorizontalScrollView ... <SortableTableView ...

I want to create several SortableTableViews, however when i scroll vertically through the screen, the vertical scrolling inside the SortableTableViews doesn't work anymore (if it has like 50 rows of data and i'm setting the height to show only 4 at once). Do you know if this is fixable?

Thanks.

Cell click event in the table

Hi,
Thanks for the library. It's really helpful.

Can you please tell me how to write click event on the each table cell to get the cell value.

Thank You
-Vinay

add own layout inflater on getView

i cant implement my public View getView on my own inside my adapter to inflate my own layout for the rows is there any way that i can make it? thanks

Set selected row backgroundColor

I'm trying to find an easy way to set (change) the background color of selected a row when its clicked on and keep the background color after sorting rows.
Do it as ListView
<ListView
....
android:choiceMode="singleChoice"
android:listSelector="#4d90fe"/>

typo issue in your readme.md

hi again and sorry for making another issue :D,

in your readme.md in Colorizer part you mentioned this code:
tableView.setDataRowColoriser(TableDataRowColorisers.alternatingRows(colorEvenRows, colorOddRows));

but it should be actually TableDataRowColori"z"ers.

How to add gesture events to SortableTableView

I want to add gesture event like swipe, double table ,longPress events to SorttableTableView how could I implement this feature. I try to add onTouchEvent to this view but does not working.

Support for Android SDK <11.

Do you plan to release a version compatible with Android SDK lower than 11. This has locked out 20% of potential users. Alternatively, what would you advise I do if need the compatibility?

Thank you.

Joe

Only shows 1 row when used in a listview.

Hi there,

I am trying to implement this TableView in a ListView. The problem is, it only shows 1 row and you have to scroll the tableview itself to see other rows. Is it a bug or am I doing something wrong? Here is what I do:

This is my JSON data:

{"Rows":[{"Column":["Karşıyaka-Bornova","Bornova-Karşıyaka"]},{"Column":["9:30","10:00"]},{"Column":["10:30","11:00"]}]}

Code:

LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

JSONObject table = new JSONObject(s10Data);
int columns = table.getJSONArray("Rows").getJSONObject(0).getJSONArray("Column").length();
int rows = table.getJSONArray("Rows").length();
List<String[]> tableList = new ArrayList<>();
TableView<String[]> tableView = new TableView(activity);
tableView.setColumnCount(columns);


for (int j = 0; j < rows; j++) {
    String[] rowItems = new String[columns];
         for (int k = 0; k < columns; k++) {
               rowItems[k] = table.getJSONArray("Rows").getJSONObject(j).getJSONArray("Column").getString(k);
                }
                tableList.add(rowItems);
           }

SimpleTableDataAdapter adapter10 = new SimpleTableDataAdapter(activity,tableList);
tableView.setDataAdapter(adapter10);
tableView.setLayoutParams(params2);
holder.innerLinearLayout.addView(tableView);

And this is what happens:

Picture

This is how it supposed to appear. (Have no idea why there is grey space on it)

Picture

Edit:
After implementing a headeradapter, it now shows header and 1 other row. Still need a solution here.

Usage of this library in your App

Hi all,

As this library is now nearly one year old, I'm very interested in which apps this library is used. Especially if this app is available in the app store.
I just want this information to use it in my references. So if you have used this lib in your app which is already published please write the app name (or maybe a link to the app store) as an answer to this issue. I'm very intereseted to see how you have used my library :)

Best regards,
Ingo

Maven Artifact of this library?

Hello Ingo,

can you please create a Maven Artifact of your library and deploy it to Maven Central? We want to use your library at work, however we use Maven as our build system and will not switch to Gradle in the near future.

Best Regards,
Luparion

Remove the TableView's internal ScrollView

This is not needed and can easily be implemented if needed. The problem due to this can be explained like this.

When I have tableView at the lower end of my LinearLayout layout (or any) where only 1 row can be visible. Then the tableView's internal scrollview starts scrolling that one row but I want to scroll all the screen up to see more than one rows. This is only possible when tableView expand itself beyond the screen in a parent scrollView which holds all the screen.

Here is my tableView layout in a LinearLayout with many siblings that are all in a ScrollView vertical.
<com.dgheating.mobileapp.Data.SortableProductTable xmlns:android="http://schemas.android.com/apk/res/android" xmlns:table="http://schemas.android.com/apk/res-auto" android:id="@+id/tableViewProducts" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@color/dividerDarkGrey" android:dividerHeight="1dip" table:columnCount="5" table:headerColor="@color/colorPrimary" />

untitled

See in the screen shot I can't scroll the screen up because tableView is not expanding based on its content.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.