001.
using
System;
002.
using
Android.App;
003.
using
Android.Content;
004.
using
Android.Runtime;
005.
using
Android.Views;
006.
using
Android.Widget;
007.
using
Android.OS;
008.
009.
using
Microsoft.WindowsAzure.MobileServices;
010.
using
Newtonsoft.Json;
011.
012.
using
System.Collections.Generic;
013.
014.
namespace
myFirstApps
015.
{
016.
public
class
MyMember
017.
{
018.
public
int
Id {
get
;
set
; }
019.
020.
[JsonProperty(PropertyName =
"name"
)]
021.
public
string
Name {
get
;
set
; }
022.
023.
[JsonProperty(PropertyName =
"email"
)]
024.
public
string
Email {
get
;
set
; }
025.
}
026.
027.
[Activity(Label =
"myFirstApps"
, MainLauncher =
true
, Icon =
"@drawable/icon"
)]
028.
public
class
MainActivity : Activity
029.
{
030.
032.
public
const
string
ApplicationKey = @
"wXYfvYuGLIaDCZdqHjTwDgeDSHZOtL94"
;
033.
034.
private
MobileServiceClient client;
035.
private
IMobileServiceTable<MyMember> memberTable;
036.
private
MyMemberAdapter mAdapter;
037.
038.
protected
override
void
OnCreate(Bundle bundle)
039.
{
040.
base
.OnCreate(bundle);
041.
042.
043.
SetContentView(Resource.Layout.Main);
044.
045.
this
.ListData();
046.
047.
}
048.
049.
public
async
void
ListData()
050.
{
051.
052.
client =
new
MobileServiceClient(ApplicationURL, ApplicationKey);
053.
memberTable = client.GetTable<MyMember>();
054.
055.
var items = await memberTable.ToListAsync();
056.
057.
ListView lstView1 = (ListView)FindViewById(Resource.Id.listView1);
058.
mAdapter =
new
MyMemberAdapter(
this
, Resource.Layout.Column, items);
059.
lstView1.Adapter = mAdapter;
060.
061.
}
062.
063.
public
class
MyMemberAdapter : BaseAdapter<MyMember>
064.
{
065.
int
layoutResourceId;
066.
Activity activity;
067.
List<MyMember> items;
068.
public
MyMemberAdapter(Activity activity,
int
layoutResourceId, List<MyMember> items)
069.
:
base
()
070.
{
071.
this
.activity = activity;
072.
this
.layoutResourceId = layoutResourceId;
073.
this
.items = items;
074.
}
075.
public
override
long
GetItemId(
int
position)
076.
{
077.
return
position;
078.
}
079.
public
override
int
Count
080.
{
081.
get
{
return
items.Count; }
082.
}
083.
public
override
View GetView(
int
position, View convertView, ViewGroup parent)
084.
{
085.
View view = convertView;
086.
if
(view ==
null
)
087.
view = activity.LayoutInflater.Inflate(Resource.Layout.Column,
null
);
088.
089.
var currentItem = items[position];
090.
091.
view.FindViewById<TextView>(Resource.Id.col_name).Text = currentItem.Name;
092.
093.
view.FindViewById<TextView>(Resource.Id.col_email).Text = currentItem.Email;
094.
return
view;
095.
}
096.
public
override
MyMember
this
[
int
position]
097.
{
098.
get
099.
{
100.
return
items[position];
101.
}
102.
}
103.
104.
}
105.
106.
}
107.
}