Skip to content

Commit fff2f2d

Browse files
committed
Updated sample and README file
1 parent 6b5c96a commit fff2f2d

File tree

95 files changed

+11528
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+11528
-2
lines changed

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
# Load-busyindicator-on-each-listviewitem-in-xamarin.forms-listview-toggle
2-
How to load busy indicator on each ListViewItem in Xamarin Forms ListView using Toggle switch
1+
# How to show busy indicator on ListViewItem using toggle switch
2+
3+
The SfListView allows to display `ActivityIndicator` for an item when loading its data in the background. To do this, load both `ActivityIndicator` and a `toggle` switch in the same row of a `Grid` element inside the `ItemTemplate` of SfListView. The busy indicator and toggle switch can be enabled and disabled by using the IsButtonVisible and IsIndicatorVisible properties respectively in the model class. The `ActivityIndicator` remains visible when the toggle switch is enabled.
4+
5+
```
6+
<ContentPage xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms">
7+
<ContentPage.BindingContext>
8+
<local:ContactInfoRepository x:Name="ViewModel" />
9+
</ContentPage.BindingContext>
10+
<syncfusion:SfListView x:Name="listView" AutoFitMode="Height" BackgroundColor="#d3d3d3" SelectionMode="None" ItemsSource="{Binding NewContactInfo}">
11+
<syncfusion:SfListView.ItemTemplate>
12+
<DataTemplate>
13+
<Frame HasShadow="True" Margin="5,5,5,0">
14+
<Grid Padding="5">
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="*" />
17+
<RowDefinition Height="*" />
18+
</Grid.RowDefinitions>
19+
<Label Text="{Binding ContactName}" FontAttributes="Bold" FontSize="19" />
20+
<Switch Grid.Row="1" Grid.Column="1" IsVisible="{Binding IsButtonVisible}" IsToggled="{Binding IsChecked}" Toggled="Switch_Toggled"/>
21+
22+
<Label Grid.Row="1" Text="{Binding ContactNo}" FontSize="15" IsVisible="{Binding IsDescriptionVisible}" />
23+
<ActivityIndicator Grid.Row="1" IsEnabled="True" IsRunning="True" IsVisible="{Binding IsIndicatorVisible}" />
24+
</Grid>
25+
</Frame>
26+
</DataTemplate>
27+
</syncfusion:SfListView.ItemTemplate>
28+
</syncfusion:SfListView>
29+
</ContentPage>
30+
```
31+
In the Toggled event of the switch, get the row data from its BindingContext and alter the Bool values accordingly.
32+
33+
```
34+
public partial class MainPage : ContentPage
35+
{
36+
private Random random = new Random();
37+
public MainPage()
38+
{
39+
InitializeComponent();
40+
}
41+
42+
private async void Switch_Toggled(object sender, ToggledEventArgs e)
43+
{
44+
var model = ((sender as Switch).BindingContext as ContactInfo);
45+
if (model.IsChecked == true)
46+
{
47+
model.ContactNo = random.Next(100, 400).ToString() + "-" + random.Next(500, 800).ToString() + "-" + random.Next(1000, 2000).ToString();
48+
model.IsDescriptionVisible = false;
49+
model.IsIndicatorVisible = true;
50+
await Task.Delay(2000);
51+
model.IsDescriptionVisible = true;
52+
model.IsIndicatorVisible = false;
53+
model.IsChecked = false;
54+
}
55+
else
56+
{
57+
model.IsIndicatorVisible = false;
58+
}
59+
}
60+
}
61+
```
62+
63+
To know more about showing busy indicator on listview items usig toggle switch, please refer our documentation [here](https://help.syncfusion.com/xamarin/sflistview/viewappearance?cs-save-lang=1&cs-lang=csharp#show-busy-indicator-on-list-view-items-using-toggle-switch).

ToggleInListViewItem/ToggleInListview.sln

Lines changed: 337 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with you package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
3+
using Android.App;
4+
using Android.Content.PM;
5+
using Android.Runtime;
6+
using Android.Views;
7+
using Android.Widget;
8+
using Android.OS;
9+
10+
namespace ToggleInListview.Droid
11+
{
12+
[Activity(Label = "ToggleInListview", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
13+
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
14+
{
15+
protected override void OnCreate(Bundle savedInstanceState)
16+
{
17+
TabLayoutResource = Resource.Layout.Tabbar;
18+
ToolbarResource = Resource.Layout.Toolbar;
19+
20+
base.OnCreate(savedInstanceState);
21+
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
22+
LoadApplication(new App());
23+
}
24+
}
25+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.ToggleInListview">
3+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="27" />
4+
<application android:label="ToggleInListview.Android"></application>
5+
</manifest>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
using Android.App;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("ToggleInListview.Android")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("ToggleInListview.Android")]
14+
[assembly: AssemblyCopyright("Copyright © 2014")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: ComVisible(false)]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
//
26+
// You can specify all the values or you can default the Build and Revision Numbers
27+
// by using the '*' as shown below:
28+
// [assembly: AssemblyVersion("1.0.*")]
29+
[assembly: AssemblyVersion("1.0.0.0")]
30+
[assembly: AssemblyFileVersion("1.0.0.0")]
31+
32+
// Add some common permissions, these can be removed if not needed
33+
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
34+
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.xml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable-hdpi/
12+
icon.png
13+
14+
drawable-ldpi/
15+
icon.png
16+
17+
drawable-mdpi/
18+
icon.png
19+
20+
layout/
21+
main.xml
22+
23+
values/
24+
strings.xml
25+
26+
In order to get the build system to recognize Android resources, set the build action to
27+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
28+
instead operate on resource IDs. When you compile an Android application that uses resources,
29+
the build system will package the resources for distribution and generate a class called
30+
"Resource" that contains the tokens for each one of the resources included. For example,
31+
for the above Resources layout, this is what the Resource class would expose:
32+
33+
public class Resource {
34+
public class drawable {
35+
public const int icon = 0x123;
36+
}
37+
38+
public class layout {
39+
public const int main = 0x456;
40+
}
41+
42+
public class strings {
43+
public const int first_string = 0xabc;
44+
public const int second_string = 0xbcd;
45+
}
46+
}
47+
48+
You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
49+
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
50+
string in the dictionary file values/strings.xml.

0 commit comments

Comments
 (0)