如何跨片段重用EmptyView?

时间:2018-07-09 00:31:04

标签: android android-fragments

在我的应用中,如果没有可用数据,我有多个片段要添加EmptyView。除了为每个片段创建一个视图之外,我如何创建一个视图并在整个片段之间重复使用?

关于该应用程序,每个片段都使用不同的REST API来填充RecyclerView。

1 个答案:

答案 0 :(得分:1)

您可以创建一个视图,对其进行充气并将其添加到父视图中。像

    public class InvoiceSale
    {
        public int Id { get; set; }
        public int BudgetId { get; set; }
        public int NumberInvoice { get; set; }
        public DateTime InvoiceSaleDate { get; set; }
        public Budget Budget { get; set; }
    }

    [HttpPost]
    public ActionResult CreateInvoiceSale(InvoiceSale newInvoiceSale)
    {
        var invoiceSale = new InvoiceSale
        {
            BudgetId = newInvoiceSale.BudgetId,
            NumberInvoice = newInvoiceSale.NumberInvoice,
            InvoiceSaleDate = newInvoiceSale.InvoiceSaleDate,
            //Here i need to pass the BudgetId value, but how can i do without a 
            //navigation property
        };
        _context.InvoiceSales.Add(invoiceSale);
        _context.SaveChanges();

        return Json("ok"):
    }

还要设置布局参数

如果要静态添加,请使用

BudgetId = newInvoiceSale.BudgetId,