fragmenttabhost第一次无法显示数据

时间:2015-01-25 04:49:07

标签: android fragment-tab-host

我正在尝试使用4个标签的fragmenttabhost,但是当我进入第一个标签时第一次无法显示数据,但是我应该点击其他标签然后返回第一个标签,数据将会显示。

我将通过API数据然后在不同的标签中显示onlistview和viewpager(图片和文本),但我不理解或丢失一些应该做的事情......

我的活动:

FragmentActivity extends ActionBarActivity

        @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);      
        tabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
        tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
        tabHost.addTab(setIndicator(this,tabHost.newTabSpec(TAB_1_TAG),0,"first tab",R.drawable.ic_launcher), firstFragment.class,null);
        ...

我的片段:

1:使用volley并获取json数据(例如:获取图片网址)

FirstTabFragment extends Fragment
onAttach(Activity activity)
        @Override
        public void onAttach(Activity activity) {
        ..
        use volley and get json data(ex:get a imagm url)...
        ...}

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.tabfragment_page1, container, false);
        return rootView;`

2.onActivityCreated:使用volley image url向pageView widge显示一些图片...

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    //use volley image url show some pictures on pageView widge...
    RequestQueue mQueue = Volley.newRequestQueue(getActivity().getApplicationContext());
    Log.d(tag,"myurl.get(i)"+promotionOneUrl.get(i));          
    ImageRequest imageRequest = new ImageRequest(promotionOneUrl.get(i),  
            new Response.Listener<Bitmap>() {  
            @Override  
            public void onResponse(Bitmap response) {  
            imageView.setImageBitmap(response);}  
            }, 0, 0, Config.RGB_565, new Response.ErrorListener() {  
            @Override  
            public void onErrorResponse(VolleyError error){                       
            R.drawable.default_image);}});
    mQueue.add(imageRequest);  
对于英语不好的人来说,p .s.aptry

0 个答案:

没有答案