Android 异步任务后更新ListFragment

Android 异步任务后更新ListFragment,android,android-asynctask,android-fragments,android-listfragment,Android,Android Asynctask,Android Fragments,Android Listfragment,我的应用程序中有两个listfragment和一个fragment。我给你们看第一个片段 应用程序启动后,Asynctask检索数据并将其放入arrayNews中。 我认为问题在于listfragment中的listview或适配器的更新没有刷新 如果我更改手机的方向=>listfragment(+listview)将正确显示。 如果我转到片段3(内存中的片段2和片段3),那么返回片段1=>它工作正常 对不起,我的英语不好^^ public类MainActivity扩展FragmentActiv

我的应用程序中有两个listfragment和一个fragment。我给你们看第一个片段

应用程序启动后,Asynctask检索数据并将其放入arrayNews中。 我认为问题在于listfragment中的listview或适配器的更新没有刷新

如果我更改手机的方向=>listfragment(+listview)将正确显示。 如果我转到片段3(内存中的片段2和片段3),那么返回片段1=>它工作正常

对不起,我的英语不好^^

public类MainActivity扩展FragmentActivity实现ActionBar.TabListener
{
私人部门SPAGERAAdapter MSECTIONSPAGERAAdapter;
私有视图寻呼机mViewPager;
公共静态ArrayList arrayNews=新ArrayList();
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List ListFragments=新向量();
add(Fragment.instantiate(这是实现Fragment.class.getName());
add(Fragment.instantiate(this,DossierFragment.class.getName());
add(Fragment.instantiate(this,ForumFragment.class.getName());
mSectionsPagerAdapter=新的SectionsPagerAdapter(getSupportFragmentManager(),ListFragments);
最终ActionBar ActionBar=getActionBar();
actionBar.setNavigationMode(actionBar.NAVIGATION\u MODE\u选项卡);
mViewPager=(ViewPager)findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOnPageChangeListener(新的ViewPager.SimpleOnPageChangeListener()
{
@凌驾
已选择页面上的公共无效(内部位置)
{
actionBar.setSelectedNavigationItem(位置);
}
});
对于(int i=0;i
使用
适配器。notifyDataSetChanged()onPostExecute
中执行code>以强制重新绘制列表。

我找到了一种更新此类列表的简单方法 步骤如下: 1.在ListFragment中声明onCreateView

public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreateView(inflater, container, savedInstanceState);
        View view = inflater.inflate(R.layout.TheLayoutContainingAListView, container, false);
        return view;        
    }
LayoutContainingListView.xml应仅包含listview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </ListView>
</LinearLayout>
showFragment只是我以前使用的一个函数
protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            lv = (ListView) findViewById(android.R.id.list);
            CustomAdapter adapt = new CustomAdapter(MainActivity.this,
                    android.R.id.list, fetch); //You can use ArrayAdapter.. i wanted a custom one
            lv.setAdapter(adapt);
            showFragment(YOUR Fragment, false);

            super.onPostExecute(result);
        }