Webservice data is not displaying in emulator

DarshanJSDarshanJS USMember ✭✭✭✭

Hi guys, i am trying bind data from webservice http://api.androidhive.info/contacts/ but when run the application it will keeps on loading in emulator
i am not aware what is the problem i have shared snapshot

and code please help me

public async void GetJSON()
    {
        //Check network status   
        if (NetworkCheck.IsInternet())
        {

            var client = new System.Net.Http.HttpClient();
            var response = await client.GetAsync("http://api.androidhive.info/contacts/");
            string contactsJson = await response.Content.ReadAsStringAsync();
            ContactList ObjContactList = new ContactList();
            if (contactsJson != "")
            {
                //Converting JSON Array Objects into generic list  
                ObjContactList = JsonConvert.DeserializeObject<ContactList>(contactsJson);
            }
            //Binding listview with server response    
            listviewConacts.ItemsSource = ObjContactList.contacts;
        }
        else
        {
            await DisplayAlert("JSONParsing", "No network is available.", "Ok");
        }
        //Hide loader after server response    
        ProgressLoader.IsVisible = false;
    }

Best Answer

Answers

  • DarshanJSDarshanJS USMember ✭✭✭✭

    Guys anyone please answer for this question i have stuck in this from two days

  • VenkataSwamyVenkataSwamy INMember ✭✭✭

    Hi @DarshanJS

    Might be problem with ActivityIndicator in XAML

    Before calling web service you need to put IsRunning="true" after getting response put IsRunning="false"

    the below code useful for thank you

      <AbsoluteLayout
            VerticalOptions="FillAndExpand"
            HorizontalOptions="FillAndExpand">
         <Grid AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All">
             <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Label Grid.Row="0" Margin="10" Text="JSON Parsing" FontSize="25" />
            <ListView x:Name="listviewConacts" Grid.Row="1" HorizontalOptions="FillAndExpand" HasUnevenRows="True" >
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid HorizontalOptions="FillAndExpand" Padding="10">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>
                                <Label Text="{Binding name}" HorizontalOptions="StartAndExpand" Grid.Row="0" TextColor="Blue"  FontAttributes="Bold"/>
                                <Label Text="{Binding email}" HorizontalOptions="StartAndExpand" Grid.Row="1" TextColor="Orange"  FontAttributes="Bold"/>
                                <Label Text="{Binding phone.mobile}" HorizontalOptions="StartAndExpand" Grid.Row="2" TextColor="Gray"  FontAttributes="Bold"/>
    
                                <BoxView HeightRequest="2" Margin="0,10,10,0" BackgroundColor="Gray" Grid.Row="3" HorizontalOptions="FillAndExpand" />
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </Grid>
         <ActivityIndicator x:Name="ProgressLoader" Color="Black" VerticalOptions="CenterAndExpand" 
       HorizontalOptions="CenterAndExpand" 
         AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"/>
     </AbsoluteLayout>
    
  • DarshanJSDarshanJS USMember ✭✭✭✭

    @Norman Mackay
    when i debug it is not going to next line after this line

    var response = await client.GetAsync("http://api.androidhive.info/contacts/");

    what may be the issue as you said whether it is a DNS issue or web service issue

  • DarshanJSDarshanJS USMember ✭✭✭✭

    @NMackay said:

    Actually i was facing internet connection issue in Android emulator instead of running the app in built in emulator, i tried to run the application by creating new AVD using Android SDK now it is working fine

  • NMackayNMackay GBInsider, University mod

    @DarshanJS

    Yeah, the build it emulators are a waste of time for anything but basic demos

Sign In or Register to comment.