I'm developing an android application, when I select a fragment, I put those code in "OnActivityCreated" such as:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
btnAdd = (ImageButton) getActivity().findViewById(R.id.imageButtonTime);
txtTime = (TextView) getActivity().findViewById(R.id.textViewTime);
txtTime.setText("");
listView = (ListView) getActivity().findViewById(R.id.listView);
time_control = new Time_Control(LoginActivity.db.getConnection());
accountID = LoginActivity.Account_Id;
calendar = Calendar.getInstance();
mYear = calendar.get(Calendar.YEAR); // current year
mMonth = calendar.get(Calendar.MONTH); // current month
mDay = calendar.get(Calendar.DAY_OF_MONTH); // current day
txtTime.setText(mDay + "/" + (mMonth + 1) + "/" + mYear);
sDate = mYear + "-" + (mMonth + 1) + "-" + mDay;
LoadList();
LoadList() is used to get data from database and put it on listview. My application load very slow when I select fragment. Is there anyway i could do to increase the performance, like putting above code to other location.
Appreciate your help!
Edit: LoadList() code:
public ArrayList<Time> LoadTime(int accId, String date) {
ArrayList<Time> arrayList = new ArrayList<Time>();
try {
PreparedStatement query = connection.prepareStatement("exec sp_excutedtask_load ?,?");
query.setInt(1, accId);
query.setString(2, date);
ResultSet resultSet = query.executeQuery();
while (resultSet.next()) {
int id = resultSet.getInt("ID");
String tagName = resultSet.getString("TagName");
String taskName = resultSet.getString("TaskName");
int esHrs = resultSet.getInt("EsHour");
int esMin = resultSet.getInt("EsMinute");
int acHrs = resultSet.getInt("AcHour");
int acMin = resultSet.getInt("AcMinute");
String start, end;
if (resultSet.getTime("Start") == null) {
start = "";
} else {
start = resultSet.getTime("Start").toString();
}
if (resultSet.getTime("End") == null) {
end = "";
} else {
end = resultSet.getTime("End").toString();
}
int run = resultSet.getInt("Running");
int done = resultSet.getInt("Done");
Time time = new Time(id, tagName, taskName, esHrs, esMin, acHrs, acMin, start, end, run, done);
arrayList.add(time);
}
} catch (SQLException e) {
e.printStackTrace();
}
return arrayList;
}