I'm trying to build an Android and I have a fragment Fragment_X
in which I read the response from the server (data of the user who logged in) and then create a table.
The fragment isn't the first to show up when the activity starts.
After the login if I select the Fragment_X
the table doesn't show up, I have to click on it another time and finally the table appears.
Is there a way to make it appear at the first time I select the Fragment_X
?
Here is my code:
Fragment_X
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_ordini, container, false);
connection = new DBConnection(c.getId(), getContext());
connection.downloadOrdiniUtente();
CookieO cookieO = new CookieO();
File ordini = new File(path);
if (ordini.exists()) {
createTable(cookieO.getOrdini(), v);
}
return v;
}
You should wait at least for 500ms when fragment created. After onCreateVeiw wait for 500ms and then make a table. for example
onCreateView() {
View view = ............
ProgressDialog dialog = new ProgressDialog(getActivity);
dialog.setMessage("Wait Please");
dialog.show();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// here u can display your table
showTable();
dialog.dismiss();
}
});
}
},500);
return view;
}