[英]Missing Data by adding a Fragment to a existing ListView
I am trying to populate my ListView with a Footer. 我试图用页脚填充ListView。 For that reason I created a Fragment.
因此,我创建了一个片段。 But I have problems passing data to the fragment.
但是我在将数据传递到片段时遇到了问题。 On a different place it worked just fine, the way I have done it.
在另一个地方,它的工作方式很好,就像我做的那样。
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);
The Fragment contains a ViewFlipper and works perfectly fine in another activity. Fragment包含一个ViewFlipper,并且在另一个活动中也可以正常工作。
Anyone a clue what I'm doing wrong or can tell me a proper way how it's done? 任何人都可以知道我在做什么错,还是可以告诉我正确的做法?
Adding a Fragment as Footer to a ListView - My solution: 将片段作为页脚添加到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);
Make sure, that footer
is inflating an empty FrameLayout like: 确保该页
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"
/>
to avoid the following bug: How to make fragment transaction when clicked on a listitem? 避免以下错误: 单击列表项时如何进行片段交易?
My result looks like this: 我的结果看起来像这样:
Hope this helps anybody :) 希望这对任何人都有帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.