片段丢失内容XAMARIN

时间:2017-04-13 13:25:38

标签: android xamarin

我有一个疑问,我在活动中有3个片段,每个片段激活它的时刻总是刷新,我希望它在'i = 0'时给出更新。我试图这样做,但片段将所有内容都返回给我空白,如果我总是必须在其选择中更新片段,则不会向我提出任何问题。我的应用程序不必在i = 0时始终更新。它完美运行所以我不希望它始终更新而且没有必要

 public class Fragment2 : SupportFragment
{
    private List<FeedItem> lista;
    private ListView feedItemsListView;
    public int i;


    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your fragment here
    }

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.Inflate(Resource.Layout.Fragment2, container, false);

        this.feedItemsListView = view.FindViewById<ListView>(Resource.Id.listView2);

        if (i == 0)
        {
            this.GetFeedItemsList();
            i = 1;
        }
        return view;
    }


    private void GetFeedItemsList()
    {
       this.progressDialog.Show();

        Task<List<FeedItem>> task1 = Task.Factory.StartNew(() =>
                                                           {
            return FeedService.GetFeedItems("url");
        }
        );

        Task task2 = task1.ContinueWith((antecedent) =>
                                        {
            try
            {
                this.progressDialog.Dismiss();
                this.lista = antecedent.Result;
                this.PopulateListView(this.lista);
            }
            catch (AggregateException aex)
            {
                Toast.MakeText (this, aex.InnerException.Message, ToastLength.Short).Show ();
            }
        }, TaskScheduler.FromCurrentSynchronizationContext()
        );
    }

    private void PopulateListView(List<FeedItem> feedItemsList)
    {
        var adapter = new FeedItemsListAdapter(Activity, feedItemsList);
        this.feedItemsListView.Adapter = adapter;
        this.feedItemsListView.ItemClick += OnListViewItemClick;
    }

    protected void OnListViewItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {

    }

0 个答案:

没有答案