Никак не могу понять, в чем дело: Когда загружаю в onCreate список listView - ничего не показывается, как только стоит выключить и включить обратно экран - список выводится. Помогите понять причину, я в ступоре. Код AsyncTask:
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
backendlessInitialize();
mProgressDialog = new ProgressDialog(ShowPUSH.this);
mProgressDialog.setTitle(text1);
mProgressDialog.setMessage(text2);
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
Typeface avenirnextregular= Typeface.createFromAsset(getAssets(), "avenirnextregular.ttf");
((TextView) mProgressDialog.findViewById(getResources().getIdentifier("alertTitle", "id", "android"))).setTypeface(avenirnextregular);
}
@Override
protected Void doInBackground(Void... params) {
worldpopulationlist = new ArrayList<notifications>();
try {
Backendless.Persistence.of( notifications.class).find(new AsyncCallback<BackendlessCollection<notifications>>(){
@Override
public void handleResponse(BackendlessCollection<notifications> notification) {
for (notifications pushes: notification.getData()){
notifications push = new notifications();
push.setPush((String) pushes.getPush());
push.setDatePush((String) pushes.getDatePush());
worldpopulationlist.add(push);
}
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Log.i ("listView33", "error: " + backendlessFault.getMessage());
}});
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
listview = (ListView) findViewById(R.id.pushes_listview);
adapter = new PUSHListViewAdapter(ShowPUSH.this, worldpopulationlist);
listview.setAdapter(adapter);
mProgressDialog.dismiss();
}
}
Полный код Активити:
public class ShowPUSH extends Activity implements SwipeRefreshLayout.OnRefreshListener {
// Declare Variables
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
PUSHListViewAdapter adapter;
private List<notifications> worldpopulationlist;
private SwipeRefreshLayout mSwipeRefreshLayout;
String text1;
String text2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.push_listview_main);
setBack();
// setIcons();
SharedPreferences preferences_blurSwitch = getSharedPreferences("TEMP_BLUR", Context.MODE_PRIVATE);
Integer blurSwitch = preferences_blurSwitch.getInt("TEMP_BLUR", 0);
if (blurSwitch == 1){
}
else{
blur();
}
swipe();
// Execute RemoteDataTask AsyncTask
new RemoteDataTask().execute();
}
public void swipe(){
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
mSwipeRefreshLayout.setOnRefreshListener(this);
mSwipeRefreshLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);
}
@Override
public void onRefresh() {
new RemoteDataTask().execute();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(false);
}
}, 4000);
}
public void backendless(){
SharedPreferences YOUR_APP_ID_sp = getSharedPreferences("BACKENDLESS_APP_ID", Context.MODE_PRIVATE);
SharedPreferences YOUR_SECRET_KEY_sp = getSharedPreferences("BACKENDLESS_SECRET_KEY", Context.MODE_PRIVATE);
SharedPreferences APP_VERSION_sp = getSharedPreferences("BACKENDLESS_APP_VERSION", Context.MODE_PRIVATE);
String YOUR_APP_ID = YOUR_APP_ID_sp.getString("BACKENDLESS_APP_ID", "");
String YOUR_SECRET_KEY = YOUR_SECRET_KEY_sp.getString("BACKENDLESS_SECRET_KEY", "");
String APP_VERSION = APP_VERSION_sp.getString("BACKENDLESS_APP_VERSION", "");
Backendless.initApp( this, YOUR_APP_ID, YOUR_SECRET_KEY, APP_VERSION );
}
Код Адаптера:
public class PUSHListViewAdapter extends BaseAdapter {
Typeface avenirnextbold;
Typeface avenirnextregular;
// Declare Variables
Context context;
LayoutInflater inflater;
private List<notifications> worldpopulationlist = null;
private ArrayList<notifications> arraylist;
public PUSHListViewAdapter(Context context, List<notifications> worldpopulationlist) {
this.context = context;
this.worldpopulationlist = worldpopulationlist;
inflater = LayoutInflater.from(context);
this.arraylist = new ArrayList<notifications>();
this.arraylist.addAll(worldpopulationlist);
}
}
public class ViewHolder {
TextView rank;
TextView country;
TextView population;
ImageView flag;
}
@Override
public int getCount() {
android.util.Log.i ("listView33", "worldpopulationlist.size(): " + worldpopulationlist.size());
return worldpopulationlist.size();
}
@Override
public Object getItem(int position) {
return worldpopulationlist.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.push_listview_item, null);
// Locate the TextViews in listview_item.xml
holder.rank = (TextView) view.findViewById(R.id.push_message);
holder.country = (TextView) view.findViewById(R.id.date_push);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.rank.setText(worldpopulationlist.get(position).getPush());
holder.country.setText(worldpopulationlist.get(position).getDatePush());
android.util.Log.i ("listView33", "older.rank.setText(worldpopulationlist.get(position).getPush());: " + worldpopulationlist.get(position).getPush());
}
holder.country.setTypeface(avenirnextbold);
holder.rank.setTypeface(avenirnextregular);
}
catch(Exception nullEx){
}
return view;
}
}