0

我从网络解析 XML,我想把这些数据放到 GridView 的其他活动中,你能帮帮我吗?

我的第一个活动:

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);
}

我的异步任务

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我应该在下载所有信息后开始另一个活动

4

1 回答 1

1

只有在下载所有信息后,我才应该开始另一个活动 => 进行如下更改:

1)仅在单击按钮时执行您的 AsyncTask

new DownloadXmlTask(this, HomeScreenActivity.this).execute("URL");

2) 在 AsyncTask 的 onPostExecute() 方法中启动 Activity:

Intent intent = new Intent(HomeScreenActivity.this, TopArtistsScreen.class);
intent.putExtra("username", username);
startActivity(intent);
于 2013-02-21T11:24:46.063 回答