My problem: This code doesn't work in my activity I am trying to implement a gridView adapter that gets data from parse.com
@Override
protected void onPostExecute(Void result) {
// Locate the gridview in gridview_main.xml
gridview = (GridView) findViewById(R.id.gridview);
// Pass the results into ListViewAdapter.java
adapter = new GridViewAdapter(MainActivity.this,
phonearraylist);
// Binds the Adapter to the ListView
gridview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}
This is within my "DiscoverActivity" class that exteds SherlockFragment
public class DiscoverActivity extends SherlockFragment
// Declare Variables
GridView gridview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ImageAdapter adapter;
private List<ImageList> phonearraylist = null;
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_discover,container,false);
// GridView gridView = (GridView) view.findViewById(R.id.gridview);
// gridView.setAdapter(new ImageAdapter(view.getContext())); // uses the view to get the context instead of getActivity().
new RemoteDataTask().execute();
return view;
}
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Toast.makeText(getActivity(), "hello",Toast.LENGTH_LONG).show();
Toast.makeText(getActivity().getApplicationContext(),"Loading...",Toast.LENGTH_LONG).show();
}
protected Void doInBackground(Void... params) {
// Create the array
phonearraylist = new ArrayList<ImageList>();
try {
// Locate the class table named "SamsungPhones" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"testData2");
// Locate the column named "position" in Parse.com and order list
// by ascending
query.orderByAscending("Price");
ob = query.find();
for (ParseObject country : ob) {
ParseFile image = (ParseFile) country.get("Photo");
ImageList map = new ImageList();
map.setPhone(image.getUrl());
phonearraylist.add(map);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
//Here is what I have tried so far...
@Override
protected void onPostExecute(Void result) {
// Locate the gridview in gridview_main.xml
gridview = (GridView) findViewById(R.id.gridview);
// Pass the results into ListViewAdapter.java
//adapter = new ImageAdapter(DiscoverActivity.this,
// phonearraylist);
GridView gridView = (GridView) view.findViewById(R.id.gridview);
gridView.setAdapter(new ImageAdapter(view.getContext())); // uses the view to get the context instead of getActivity().
// Binds the Adapter to the ListView
gridview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}
I am undable to findViewById in my onPostExecute
Thanks in advance for any help you can give me!
have you wrote this statement in the onCreate method? (of the activity)
then you can use all id's defined there.