Reputation: 36404
public class HomeActivity extends Activity{
// public ArrayList<User> users1 = new ArrayList<User>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// ListView lv = (ListView) findViewById(R.id.user_crumbs_list);
final ArrayList<User> users1 = new ArrayList<User>();
User user = null;
class AsyncLoader extends AsyncTask<User,Void, ArrayList<User>> {
ProgressDialog dialog;
@Override
protected void onPreExecute(){
dialog = new ProgressDialog(HomeActivity.this); // App - your main activity class
dialog.setMessage("Please, wait...");
dialog.show();
}
@Override
protected ArrayList<User> doInBackground(User... users) {
String response = "";
for (User user:users)
try {
try {
user = new User("4eeb34c6d80e8f1214000000");
user.getFollowingCrumbsUpList();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(User u : user.following){
users1.add(u);
}
} catch (Exception e) {
e.printStackTrace();
}
return users1;
}
protected void onPostExecute(String result) {
dialog.dismiss();
return;
}
}
AsyncLoader task = new AsyncLoader();
task.execute(user);
setContentView(R.layout.user_main_tab_home);
final UserFollowingListAdapter csl = new UserFollowingListAdapter(this,R.layout.user_list_item,users1,this);
ListView lv = (ListView) findViewById(R.id.user_list);
public void showError(){
new AlertDialog.Builder(this)
.setTitle(" Oops , Server down :( ")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
}
//
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}).show();
}
}
This is going on an infinite loop where the data doesn't load at all and the dialog goes on an infinite loop till I click on it. My goal is to load some initial amount of data and then fetch data as per the user scroll. As of now, I'm not even able to display the data.
After debugging I found out that user1 variable has no values stored in it, which I'm not able to find out why, even though the iteration is taking place.
Any clues as to where I am going wrong?
Upvotes: 0
Views: 259
Reputation: 8176
I really can't follow what you're trying to do, but the problem likely lies in the fact that, at the time you call task.execute(user);
, user
is null. So the for (User user:users)
in your AsyncTask has no items to iterate over.
Upvotes: 1