Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMatheus G Oliveira
9,682 PointsWhat am i doing wrong? Displaying text on a ListFragment
Hey guys, i am trying to show an array list retrieving strings from a ParseObject to show in a ListView in a ListFragment but it isnt showing, it isnt even creating the arrays.
can you help me to show whats wrong with my code?
public class CampeonatosFragment extends ListFragment {
ListView campeonatoListView;
ArrayList<String> campeonatoArray = new ArrayList<String>();
ProgressBar mProgressBar;
CampAsyncTask cs;
protected final static String TAG = CampeonatosFragment.class.getSimpleName();
Context context;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
}
public class CampAsyncTask extends
AsyncTask<Object, Void, List<ParseObject>> {
@Override
protected List<ParseObject> doInBackground(Object... params) {
mProgressBar.setVisibility(View.VISIBLE);
List<ParseObject> campeonatosF = new ArrayList<ParseObject>();
ParseQuery<ParseObject> query = ParseQuery.getQuery("CampName");
try {
campeonatosF = query.find();
} catch (ParseException e) {
Log.e(TAG, "Caught Exception : " + e.getMessage(), e);
}
return campeonatosF;
}
@Override
protected void onPostExecute(List<ParseObject> campeonatosF) {
mProgressBar.setVisibility(View.INVISIBLE);
for (int i = 0; i < campeonatosF.size(); i++) {
campeonatoArray.add(campeonatosF.get(i).getString("NomeCampe onato"));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,
android.R.layout.simple_list_item_1, android.R.id.text1,
campeonatoArray);
campeonatoListView.setAdapter(adapter);
}
}
}