Should I prefer rendering layout at run time or Include it in XML layout?

58 Views Asked by At

I need to show a "No data found" message on many screens in my app. For that I created a separate layout with message and image; Now,I'm not sure whether I should include that layout in all other activities' layout or render this layout at runtime? What would be more efficient? Any suggestion is appreciable.

Thanks;

1

There are 1 best solutions below

3
On

I use a textview with text : "No data found" in all layouts and set VISIBILITY GONE or VISIBLE according to api result. Or you can add view to your main layout if no data found. Like this;

public showAlert(LinearLayout layout){
    TextView textView= new TextView(context);
    textView.setText("No data found");
    layout.addView(textView);
}

Write this function in a class and call everywhere you want