Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with table view. #99

Closed
renevl opened this issue May 15, 2017 · 19 comments
Closed

Problem with table view. #99

renevl opened this issue May 15, 2017 · 19 comments
Assignees

Comments

@renevl
Copy link

renevl commented May 15, 2017

Im using this control but when I try to show the data in the tableview, it doesn´t appear anything.

table_products.setVisibility(View.VISIBLE); table_adapter=new cTableAdapter(getBaseContext(),res_array.get(4)); table_adapter.setData_array(res_array.get(4)); table_products.setDataAdapter(table_adapter);
`public class cTableAdapter extends TableDataAdapter<Object[]>
{

private ArrayList<Object[]>data_array;
public cTableAdapter(Context context, ArrayList<Object[]> data) {
    super(context, data);
}

public void setData_array(ArrayList<Object[]> data_array) {
    this.data_array = data_array;
}

@Override
public View getCellView(int rowIndex, int columnIndex, ViewGroup parentView) {
   switch (columnIndex)
   {
       case 0:return renderColumn0(parentView);
       case 1:return renderColumn1(parentView,columnIndex,rowIndex);
       default:return renderColumn2(columnIndex,rowIndex);
   }
}

private View renderColumn0(ViewGroup parentView)
{
    View viewfst=getLayoutInflater().inflate(R.layout.table_view_adapter,parentView,false);
    CheckBox cellfst=(CheckBox)viewfst.findViewById(R.id.cbx_column);
    cellfst.setChecked(false);
    return viewfst;
}
private View renderColumn1(ViewGroup parentView,int columnIndex,int rowIndex)
{
   View view=getLayoutInflater().inflate(R.layout.table_view_adapter_1,parentView,false);
   TextView cell=(TextView) view.findViewById(R.id.txt_column);
   cell.setText(data_array.get(rowIndex)[columnIndex].toString());
   return view;
}
private View renderColumn2(int columnIndex,int rowIndex)
{
    final TextView textView = new TextView(getContext());
    textView.setText(data_array.get(rowIndex)[columnIndex].toString());
    textView.setPadding(20, 10, 20, 10);
    return textView;
}

}
`
I don´t know what is missing.

@ISchwarz23
Copy link
Owner

Hi @renevl,

first I would remove the setData_array() method to ensure the functionality of the adapter. To access the data passed via the constructor call the getRowData(rowIndex) method.

But the rest looks fine. May you can check if there is some data in res_array.get(4).

Best regards,
Ingo

@ISchwarz23 ISchwarz23 self-assigned this May 16, 2017
@renevl
Copy link
Author

renevl commented May 16, 2017

I removed the method and I verified the var res_array but the table still no showing data.

@ghost
Copy link

ghost commented May 16, 2017 via email

@renevl
Copy link
Author

renevl commented May 16, 2017

When I debugg, the list or the method getRowData return a Object array that have data but the data doesn´t showed in the tableview.

@ISchwarz23
Copy link
Owner

Please try this adapter:

public class cTableAdapter extends TableDataAdapter<Object[]>{

    public cTableAdapter(Context context, ArrayList<Object[]> data) {
        super(context, data);
    }

    @Override
    public View getCellView(int rowIndex, int columnIndex, ViewGroup parentView) {
        switch (columnIndex) {
            case 0: return renderColumn0(parentView);
            case 1: return renderColumn1(parentView,columnIndex,rowIndex);
            default: return renderColumn2(columnIndex,rowIndex);
         }
    }

    private View renderColumn0(ViewGroup parentView) {
        View viewfst = getLayoutInflater().inflate(R.layout.table_view_adapter,parentView,false);
        CheckBox cellfst = (CheckBox)viewfst.findViewById(R.id.cbx_column);
        cellfst.setChecked(false);
        return viewfst;
    }

    private View renderColumn1(ViewGroup parentView,int columnIndex,int rowIndex) {
        View view=getLayoutInflater().inflate(R.layout.table_view_adapter_1,parentView,false);
        TextView cell = (TextView) view.findViewById(R.id.txt_column);
        cell.setText(getRowData(rowIndex)[columnIndex].toString());
        return view;
    }

    private View renderColumn2(int columnIndex, int rowIndex) {
        final TextView textView = new TextView(getContext());
        textView.setText(getRowData(rowIndex)[columnIndex].toString());
        textView.setPadding(20, 10, 20, 10);
        return textView;
    }
}

As improvement: Don't inflate the cell layouts, but create the View itself, like you did in renderColumn2.

@renevl
Copy link
Author

renevl commented May 16, 2017

I have my code like this:
`public class cTableAdapter extends TableDataAdapter<Object[]>
{

private Object[]data_row;

public cTableAdapter(Context context, ArrayList<Object[]> data) {
    super(context, data);
}

@Override
public View getCellView(int rowIndex, int columnIndex, ViewGroup parentView) {
   data_row=getRowData(rowIndex);
    View renderedView;
   switch (columnIndex)
   {
       case 0:
           renderedView =renderColumn0();
       break;
       default:
           renderedView = renderColumn1(columnIndex);
       break;
   }
   return renderedView;
}

private View renderColumn0()
{
   CheckBox cbx_column=new CheckBox(getContext());
   cbx_column.setChecked(false);
   return cbx_column;
}

private View renderColumn1(int columnIndex)
{
    TextView textView = new TextView(getContext());
    textView.setText(data_row[columnIndex].toString());
    textView.setPadding(20, 10, 20, 10);
    return textView;
}

}
`

@renevl
Copy link
Author

renevl commented May 16, 2017

and still no showing data
tableview

@ghost
Copy link

ghost commented May 16, 2017 via email

@renevl
Copy link
Author

renevl commented May 16, 2017

image

@renevl
Copy link
Author

renevl commented May 16, 2017

getRowData has data

@ISchwarz23
Copy link
Owner

Strange. When I use the Adapter you posted most recently, I see the data.
This is how I my data:

final ArrayList<Object[]> data = new ArrayList<>();
data.add(new Object[]{"This", "is", "a", "test"});

final SortableTableView<Object[]> tableView = (SortableTableView) findViewById(R.id.tableView);
tableView.setDataAdapter(new cTableAdapter(this, data));

And I see a table like this:
| (ChekckBox) | is | a | test |

@renevl
Copy link
Author

renevl commented May 16, 2017

Do the table has to be SortableTableView? because I put only a TableView.

@ISchwarz23
Copy link
Owner

No, the SortableTableView just provides the possibility for the user to sort the data.

@renevl
Copy link
Author

renevl commented May 16, 2017

and Do I need to create another class? i just use the adapter and the main activity.

@ISchwarz23
Copy link
Owner

ISchwarz23 commented May 16, 2017

No, you don't need more. As mentioned for me it is working with the code above. I just checked it with the simple TableView and it is also working:

final ArrayList<Object[]> data = new ArrayList<>();
data.add(new Object[]{"This", "is", "a", "test"});

final TableView<Object[]> tableView = (TableView) findViewById(R.id.tableView);
tableView.setDataAdapter(new cTableAdapter(this, data));

Can you post the layout file which contains the TableView?

@renevl
Copy link
Author

renevl commented May 16, 2017



<com.getbase.floatingactionbutton.FloatingActionsMenu
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/menu_buttons"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
fab:fab_expandDirection="left"
fab:fab_addButtonColorNormal="?attr/colorPrimary"
fab:fab_addButtonColorPressed="@color/colorPrimaryDark"
fab:fab_addButtonSize="normal"
android:layout_marginBottom="15dp"
>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_search_order"
fab:fab_size="mini"
fab:fab_colorNormal="?attr/colorAccent"
fab:fab_colorPressed="@color/colorPrimaryDark"
fab:fab_icon="@drawable/search"
/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_authorize_order"
fab:fab_size="mini"
fab:fab_colorNormal="?attr/colorAccent"
fab:fab_colorPressed="@color/colorPrimaryDark"
fab:fab_icon="@drawable/authorize"
/>
<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_reject_order"
fab:fab_size="mini"
fab:fab_colorNormal="?attr/colorAccent"
fab:fab_colorPressed="@color/colorPrimaryDark"
fab:fab_icon="@drawable/reject"
/>
</com.getbase.floatingactionbutton.FloatingActionsMenu>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/lay_spinner_filter_0"
            android:weightSum="100"
            android:layout_marginBottom="20dp">
            <Spinner
                android:id="@+id/sp_client"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                style="@style/spinner_style">
            </Spinner>

            <Spinner
                android:id="@+id/sp_store"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                style="@style/spinner_style"
                >
            </Spinner>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/lay_spinner_filter_1"
            android:weightSum="100"
            android:layout_marginBottom="30dp">
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:id="@+id/til_document"
                >
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/edt_document"
                    android:singleLine="true"
                    android:hint="@string/edt_document"
                    android:inputType="number"
                    android:textColor="@color/colorPrimary"
                    />
            </android.support.design.widget.TextInputLayout>

            <Spinner
                android:id="@+id/sp_reason"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="50"
                android:layout_marginLeft="5dp"
                android:layout_marginStart="5dp"
                style="@style/spinner_style"
                android:layout_gravity="center"
                >
            </Spinner>

        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/txt_title"
            android:text="@string/txt_title"
            android:textColor="@color/colorPrimary"
            android:layout_marginBottom="5dp"
            android:visibility="gone"
        />
        <View
            android:layout_width="fill_parent"
            android:layout_height="1dp"
            android:background="@color/colorPrimaryDark"
            android:id="@+id/view_separator"
            android:layout_marginBottom="20dp"
            android:visibility="gone"
        />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/lay_info_order_titles"
            android:orientation="horizontal"
            android:weightSum="100"
            android:visibility="gone"
            >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/txt_document_title"
                android:textAlignment="center"
                android:layout_weight="37"
                android:layout_gravity="center"
                android:text="@string/txt_document_title"
                android:textColor="@color/colorPrimary"
                />
            <TextView
                android:id="@+id/txt_client_title"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="26"
                android:layout_gravity="center"
                android:textAlignment="center"
                android:text="@string/txt_client_title"
                android:textColor="@color/colorPrimary"
                >
            </TextView>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/txt_amount_title"
                android:id="@+id/txt_amount_title"
                android:textAlignment="center"
                android:layout_weight="37"
                android:layout_gravity="center"
                android:textColor="@color/colorPrimary"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/lay_info_order"
            android:orientation="horizontal"
            android:weightSum="100"
            android:visibility="gone"
            android:layout_marginBottom="20dp"
        >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/txt_document"
                android:textAlignment="center"
                android:layout_weight="37"
                android:layout_gravity="center"
                android:textColor="@color/colorPrimary"
            />
            <Spinner
                android:id="@+id/sp_tran_client"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="26"
                style="@style/spinner_style"
                >
            </Spinner>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/txt_amount"
                android:textAlignment="center"
                android:layout_weight="37"
                android:layout_gravity="center"
                android:textColor="@color/colorPrimary"
                />
        </LinearLayout>
        <de.codecrafters.tableview.TableView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/table_products"
            android:visibility="gone"
            fab:tableView_columnCount="5"
            fab:tableView_headerElevation="5"
            fab:tableView_headerColor="@color/colorPrimary"
            >

        </de.codecrafters.tableview.TableView>
    </LinearLayout>
</RelativeLayout>

This is the layout

@ISchwarz23
Copy link
Owner

I guess the issue is, as your layout is pretty complex and the height is set to "wrap_content" the data is inside the table, but the height is 0. So you can try to set the height to an absulute value e.g. 100px.

@renevl
Copy link
Author

renevl commented May 16, 2017

Yes, that resolve my problem thank you very much

@renevl
Copy link
Author

renevl commented May 16, 2017

Now I need it when I look for different filters, the tableview will refresh. Can I do that?

@renevl renevl closed this as completed May 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants