0

我需要更改我在适配器FragmentView pager 有 getItem 方法View pager

    @Override
    public Fragment getItem(int position) {

    fragmentPosition = position;
    Log.e("PageAdapter", "Creating fragment at: " + position);
    DefinedValues.thumbnailInfo.put("activity", DefinedValues.images);
    DefinedValues.thumbnailInfo.put("type", "info");
    DefinedValues.thumbnailInfo.put("page", position+ 1 + "");

    String request = Json.stringToJson(DefinedValues.thumbnailInfo);
    DefinedValues.thumbnailInfo.clear();

    StringAsyncRetriever net = new StringAsyncRetriever();
    net.setListener(MyPagerAdapter.this);
    net.execute(request, DefinedValues.GET_DATA);
    Log.d(TAG, "got item @ " + position);

    fragment1 myFragment = new fragment1();
    return myFragment;
}

我需要在 AsyncTask 完成后将其更改为显示图像的那个

有 fragment1 类:

    public class fragment1 extends Fragment {

GridView gridView;
public ImageAdapter adapter;
public int position;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        //
        Bundle savedInstanceState) {

    adapter = new ImageAdapter(this.getActivity(), position);


    if (container == null) {
        Log.e("Null container", "Null");
        return null;
    }
    //Log.e("fragment1", "fragment1 reached!");
    View view =  inflater.inflate(R.layout.menu1_fragment, container, false);
    gridView = (GridView)view.findViewById(R.id.gridview1);

    gridView.setAdapter(adapter);
    DefinedValues.adapterContainer.add(adapter);
    //Log.d("Fragment1 adapter count: ", DefinedValues.adapterContainer.size() + "");


/*  gridView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            ImageView imageView = new ImageView(getActivity());
            LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams
                    (LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            imageView.setLayoutParams(vp);

            imageView.setImageBitmap(DefinedValues.imageContainer.get(position).getThumbnail());
            getActivity().addContentView(imageView, vp);
        }


    });
    */


    return gridView;
}

那么如何仅在 asyncTask 结束时将 gridView 添加到片段?

4

1 回答 1

0

你应该让ViewPager处理片段的变化。您可以在getItem. 只需隐藏该片段中的所有内容,并可选择渲染您正在执行的其他内容FragmentDummy。然后,将片段传递给您的 AsyncTask 或通过 AsyncTask 中的 id/tag 获取片段。然后,您可以在任务完成后在片段中显示正确的内容视图并隐藏片段的虚拟部分。

于 2013-01-03T10:04:40.357 回答