Set first row to column name and adjust column width

折月煮酒 提交于 2019-12-24 10:09:19

问题


I have a problem. I created a GridView with a custom adapter. The GridView looks like this:

As you can see the column names are not aligned with the column itself, because the column names are textviews. So I want to do something like, when the gridview gets filled and its on the first row, you first print the column names. The result I want is this:

And when that is done, I want to adjust the column width for the whole column to the longest value that. So when I only have Buy and Sell, I want the column Action to buy as long as the name Action, because that is the longest value. But when there comes a value Withdrawal, it will be as long as that name. Here is the most important code of my GridViewAdapter:

public class OrderListAdapter : BaseAdapter<order>
{
    public List<order> mItems;
    private Context mContext;

    public OrderListAdapter(Context context, List<order> items)
    {
        mItems = items;
        mContext = context;
    }

    public override int Count
    {
        get { return mItems.Count; }
    }

    public void refresh(List<order> mItems)
    {
        this.mItems = mItems;
        NotifyDataSetChanged();
    }

    public override long GetItemId(int position)
    { 
        return position;
    }

    public override order this[int position]
    {
        get { return mItems[position]; }
    }

    public override View GetView(int position, View convertView, ViewGroup parent)
    {

        View row = convertView;

        if (row == null)
        {
            row = LayoutInflater.From(mContext).Inflate(Resource.Layout.orderlist_row, null, false);

            var txtOrderAction = row.FindViewById<TextView>(Resource.Id.txtOrderAction);
            var txtOrderCoin = row.FindViewById<TextView>(Resource.Id.txtOrderCoin);
            var txtOrderQuantity = row.FindViewById<TextView>(Resource.Id.txtOrderQuantity);
            var txtOrderPrice = row.FindViewById<TextView>(Resource.Id.txtOrderPrice);
            var txtOrderStatus = row.FindViewById<TextView>(Resource.Id.txtOrderStatus);
            var txtOrderProfit = row.FindViewById<TextView>(Resource.Id.txtOrderProfit);
            var LayoutProfit = row.FindViewById<LinearLayout>(Resource.Id.LayoutProfit);

            row.Tag = new OrderViewHolder() {
                txtOrderAction = txtOrderAction,
                txtOrderCoin = txtOrderCoin,
                txtOrderQuantity = txtOrderQuantity,
                txtOrderPrice = txtOrderPrice,
                txtOrderStatus = txtOrderStatus,
                txtOrderProfit = txtOrderProfit,
                LayoutProfit = LayoutProfit };
        }

        var holder = (OrderViewHolder)row.Tag;

        return row;
    }
}

With Order.cs:

public class order
{
    public int Id { get; set; }
    public int AgentId { get; set; }
    public string Action { get; set; }
    public string Market { get; set; }
    public string Coin { get; set; }
    public decimal Quantity { get; set; }
    public decimal Amount { get; set; }
    public decimal LimitValue { get; set; }
    public decimal TriggerValue { get; set; }
    public decimal Price { get; set; }
    public decimal Trans_Quantity { get; set; }
    public decimal Trans_Amount { get; set; }
    public decimal Trans_Price { get; set; }
    public decimal Trans_Fee_Coin { get; set; }
    public decimal Trans_Fee_USDT { get; set; }
    public decimal Trans_USDT { get; set; }
    public string Status { get; set; }
    public string State { get; set; }
    public DateTime DateTimeEntered { get; set; }
    public DateTime DateTimePlanned { get; set; }
    public DateTime DateTimeExecuted { get; set; }
    public string Remark { get; set; }
    public string Strategy { get; set; }
    public decimal ProfitUSDT { get; set; }
    public decimal ProfitPerc { get; set; }

}

来源:https://stackoverflow.com/questions/56439817/set-first-row-to-column-name-and-adjust-column-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!