I parse XML from web and I want to put this data to GridView in other activity, can you help me?
My first activity:
public class HomeScreenActivity extends Activity {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.imageButton:
Intent intent = new Intent(this, TopArtistsScreen.class);
intent.putExtra("username", username);
new DownloadXmlTask(this, HomeScreenActivity.this)
.execute("URL");
startActivity(intent);
}
My AsyncTask
public class DownloadXmlTask extends AsyncTask<String, Void, List<Artist>> {
@Override
protected void onPostExecute(List<Artist> result) {
progressDialog.dismiss();
gridView.setAdapter(new TopArtistsImageAdapter(context, result));
}
TopArtistsImageAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if(convertView==null) {
view = inflater.inflate(R.layout.items, null);
}
TextView textView = (TextView) view.findViewById(R.id.grid_item_name);
ImageView imageView = (ImageView) view.findViewById(R.id.grid_item_image);
textView.setText(artistsList.get(position).getName());
imageLoader.DisplayImage(artistsList.get(position).getImage(), imageView);
return view;
}
PS I shoud start another activity only after downloading all information
I shoud start another activity only after downloading all information => Make changes as below:
1) Only execute your AsyncTask on button click
new DownloadXmlTask(this, HomeScreenActivity.this).execute("URL");
2) Start Activity inside onPostExecute() method of your AsyncTask:
Intent intent = new Intent(HomeScreenActivity.this, TopArtistsScreen.class);
intent.putExtra("username", username);
startActivity(intent);