0

我正在尝试使用页脚填充我的 ListView。出于这个原因,我创建了一个片段。但是我在将数据传递给片段时遇到问题。在不同的地方它工作得很好,就像我做的那样。

    listView1 = (ListView) findViewById(R.id.listView1);     

    MenueAdapter adapter = new MenueAdapter(MainActivity.this,
            R.layout.mainview_menue_item_row, data_Storage_news, 
            getWindowManager().getDefaultDisplay().getWidth());    


    Intent intent_onTv = new Intent(context,
            OnTvFragment.class);

    intent_onTv.putExtra("data_Storage_tv", data_Storage_tv);

    OnTvFragment frag = new OnTvFragment();
    frag.setArguments(intent_onTv.getExtras());
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();        
    ft.commit();    

    LayoutInflater inflater = getLayoutInflater();      
    View footer = inflater.inflate(R.layout.ontv_fragment, null);       

    getSupportFragmentManager().executePendingTransactions();

    listView1.addFooterView(footer);       
    listView1.setAdapter(adapter);

Fragment 包含一个 ViewFlipper 并且在另一个活动中工作得很好。

任何人都知道我做错了什么,或者可以告诉我正确的方法吗?

4

1 回答 1

0

将片段作为页脚添加到 ListView - 我的解决方案:

ListView.LayoutParams lp = new ListView.LayoutParams(ListView.LayoutParams.WRAP_CONTENT, ListView.LayoutParams.WRAP_CONTENT);        

    View footer = new View(listView1.getContext()); 

    footer = ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.on_tv_fragment_empty, null);        
    footer.setLayoutParams(lp);     

    OnTvFragment frag = new OnTvFragment();
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();        
    ft.replace(R.id.ll, frag).commit();       
    getSupportFragmentManager().executePendingTransactions();

    listView1.addFooterView(footer);
    listView1.setAdapter(adapter);

确保这footer是在膨胀一个空的 FrameLayout,例如:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"     
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"   
    android:background="@layout/gradient_box"
    android:id="@+id/ll"
    />        

避免以下错误: 单击列表项时如何进行片段事务?

我的结果如下所示: 在此处输入图像描述

希望这对任何人都有帮助:)

于 2013-03-26T11:55:00.693 回答