0

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

WOLVERINE
  • 769
  • 3
  • 12
  • 28

1 Answers1

1

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);
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • 1
    How can i put my ArrayList to Extra? Artist looks like Artist(String, String, String, String) – WOLVERINE Feb 21 '13 at 12:27
  • 1
    For passing user-defined object from one screen to another, refer this [example](http://www.technotalkative.com/android-send-object-from-one-activity-to-another-activity/) – Paresh Mayani Feb 21 '13 at 12:51