Help with converting ienumerables to array. Parse

HarshShahHarshShah USMember
edited August 2014 in Xamarin.Android

This is my code in my tree class.

public static async Task<ParseObject[]> gettrees()
{

        var query = ParseObject.GetQuery ("Tree")
            .WhereEqualTo ("adder", ParseUser.CurrentUser)
            .WhereEqualTo ("added", ParseUser.CurrentUser);


        IEnumerable<ParseObject> result = await query.FindAsync();
        ParseObject[] results=result.ToArray();
        return results;
    }

I am trying to convert the ienumerable to an array before returning it

In my activity, I have this code below. The reason i am using the .result is because i want to convert the task to a parseobject. I do not want to have an async function and "await" what the gettree function returns.

int x = mytrees.Length;
ParseObject[] mytrees = UnityTreeApp.Tree.gettrees ().Result;
string[] items = new string[x];

        for (int i = 0; i < mytrees.Length; i++) {
            items [i] = mytrees [i].Get<string> ("tree_name");
        }



        var testlist = FindViewById<ListView> (Resource.Id.listView1);
        testlist.Adapter = new ArrayAdapter (this, global::Android.Resource.Layout.SimpleListItem1, items);

The listview is not working at all and I am not sure if it is because the ienumerable is not being converted to an array in the gettree function, or if something is going on with .result.

Posts

  • HarshShahHarshShah USMember

    This is my code in my tree class.

        public static async Task<ParseObject[]> gettrees()
        {
    
            var query = ParseObject.GetQuery ("Tree")
                .WhereEqualTo ("adder", ParseUser.CurrentUser)
                .WhereEqualTo ("added", ParseUser.CurrentUser);
    
    
            IEnumerable<ParseObject> result = await query.FindAsync();
            ParseObject[] results=result.ToArray();
            return results;
        }
    

    I am trying to convert the ienumerable to an array before returning it

    In my activity, I have this code below. The reason i am using the .result is because i want to convert the "task" to a "parseobject". I do not want to have an async function and "await" what the gettree function returns.

            int x = mytrees.Length;
            ParseObject[] mytrees = UnityTreeApp.Tree.gettrees ().Result;
            string[] items = new string[x];
    
            for (int i = 0; i < mytrees.Length; i++) {
                items [i] = mytrees [i].Get<string> ("tree_name");
            }
    
    
    
            var testlist = FindViewById<ListView> (Resource.Id.listView1);
            testlist.Adapter = new ArrayAdapter (this, global::Android.Resource.Layout.SimpleListItem1, items);
    

    The listview is not working at all and I am not sure if it is because the ienumerable is not being converted to an array in the gettree function, or if something is going on with .result.

    Sorry I reposted because of the weird format that it was orginally posted with

Sign In or Register to comment.