ISchwarz23 / SortableTableView

An Android library containing a simple TableView and an advanced SortableTableView providing a lot of customisation possibilities to fit all needs.
Apache License 2.0
1.05k stars 239 forks source link

CheckBox to TableHeaderAdapter #195

Open IranthaJ opened 4 years ago

IranthaJ commented 4 years ago

I am using this table view and trying to create a table with a header checkbox and checkbox for each row. Something like below; image

I was able to render checkboxes in rows but could not find a way to set it in the header with 'SimpleTableHeaderAdapter'. Is there a way to include views in the header?

I only see these constructors;

public SimpleTableHeaderAdapter(Context context, params string[] headers);
public SimpleTableHeaderAdapter(Context context, params int[] headerStringResources);

Note: I am working with Xamarin C# - https://github.com/xamarin/XamarinComponents/tree/master/Android/SortableTableView

IranthaJ commented 4 years ago

I got to know that we can use customized TableHeaderAdapter as our Data adapter. I was successful with the following example

public class CustomTableHeaderAdapter : TableHeaderAdapter 
{
    public CustomTableHeaderAdapter(Context context)
    {
        super(context);
    }
   public override View GetHeaderView(int columnIndex, ViewGroup parentView)
   {
        switch( columnIndex ) 
        {
            case 0: return RenderCheckBox();
            case 1: return RenderTextCell( "Column header");
            default: return null;
        }
    }
        private View RenderTextCell(string text)
        {
            var textView = new TextView(this.Context);
            textView.Text = text;
            return textView;
        }
        private View RenderCheckBox()
        {
            CheckBox checkBox = new CheckBox(this.Context);
            checkBox.Click += HeaderCheckBox_Click;
            return checkBox;
        }
}