Forum Xamarin.Android

List Fragment frustration - cannot get it to show

Hi All,

I'm new to Xamarin and android code and trying to understand what's going on. I've been trying to load a list fragment and been through all the examples I could find online. Of course it's not a simple example, so here's my scenario:

What I want to do is within an activity I want to either give the user the choice to pick from a list or enter data manually. There are 3 items of data that I want to collect that are progressive. The 3 data lists to show are populated from WCF async web service calls. I have a UI that has 4 Text views (populated from the lists or by user input) and some buttons.

Conceptually the idea is that the user clicks a button and the first list loads. They make a selection and it populates the EditText, or they cancel and have to manually input the data. Then they click the button again and the data in the EditText is used to populate the next list. Once all 3 are collected, they enter a quantity and send the data back to SQL via the web service call.

In my button code I look to see what has been filled in so that I know what the next item to collect is. I make the async call and in the runonuithread I set an array adapter then call the code that creates the fragmentmanager transaction.

I can walk through the code and it seems to do everything correctly, but the list fragment is never shown. Can anyone help point me in the right direction?

Here's the relevant code:

Section of Button Click code to populate the List

        //Shows the list dialogs - uses wodetails to determine what list to show
        void btnnext_Click(object sender, EventArgs e)
            {

            string sRes = string.Empty;


            //  Determine what to do and which list to show

            //Need WO No
            if (_WODetails.WONo == "")
                {

                //get the list of WONos (async) 
                _client.GetWOListAsync(-5);

The first list async call :

//Get WO List Async call (via Proxy Class)
        private void clientGetWOListAsync(object sender, GetWOListCompletedEventArgs EventArgs)
            {
            string msg = null;

            if (EventArgs.Error != null)
                {
                msg = EventArgs.Error.Message;
                }
            else if (EventArgs.Cancelled)
                {
                msg = "Request was cancelled.";
                }
            else
                {
                msg = EventArgs.Result;
                }

            //RunOnUiThread(() => _WCFReturn = msg);
            RunOnUiThread(() =>
            {
                _WCFReturn = msg;

                if (_MyListAdapter == null)
                    {
                     _MyListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItemSingleChoice, _WCFReturn.Split(','));
                    _ListAdapter = _MyListAdapter;
                    }
                else
                    {
                    _MyListAdapter.NotifyDataSetChanged();
                    }
                ShowWOList();

            });

ShowWOList code

//Create and populate the Work Order list
        private void ShowWOList()
            {

            //Call the list fragment and get the data returned
            var transaction = FragmentManager.BeginTransaction();
            var dialogFragment = new SelectDialogFragment(this, "Work Order", _sReply);

            transaction.Add(dialogFragment, "WO_fragment");
            transaction.Commit();

            }

Fragment Code

    //
        //      List view  Dialog Fragment code
        //

        public class SelectDialogFragment : ListFragment
            {

            //Create the class properties
            private string _Selected = "";
            public string Selected
                {
                get { return _Selected; }
                set { _Selected = value; }
                }

            private readonly Context _context;
            private readonly string _type;



            public override void OnCreate(Bundle savedInstanceState)
                {
                base.OnCreate(savedInstanceState);
                // Create your fragment here
                }

            public SelectDialogFragment(Context context, string sType, string sList)
                {

                _context = context;
                _type = sType;


                }

            //Create the view 
            public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
                {

                var view = inflater.Inflate(Resource.Layout.dialoglayout, container, false);

                return view;

                }


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

                //this.ListAdapter = new ArrayAdapter<String>(_context, Android.Resource.Layout.SimpleListItemSingleChoice, _list);
                this.ListAdapter = _ListAdapter;

                }


            public override void OnListItemClick(ListView l, View v, int position, long id)
                {
                //_Selected = _list[position];

                _Selected = Convert.ToString(this.ListAdapter.GetItem(position));

                ((SelectActivity)this.Activity)._Selectedstring = Convert.ToString(this.ListAdapter.GetItem(position));

                }


            }

Fragment Layout axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp">
    <ListView xmlns:iosched="http://schemas.android.com/apk/res-auto"
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawSelectorOnTop="false" />
    <TextView
        android:id="@id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="No data returned - Enter data below" />
    <TextView
        android:text="@string/dialog_hdr"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lblhdr" />
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtnumber" />
    <Button
        android:text="Select"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/CloseButton"
        android:layout_marginTop="10dp" />
</LinearLayout>
Sign In or Register to comment.