Reputation: 253
i am newbie in xamarin android app in c#. i have created page activity which intends to fill listview with array named plays.it successfully shows listview with array items. when i click on listview item nothing happen. it should start new activity depending upon position of item. I think there is problem with listv.itemclick event handler. the pageActivity is as follows:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Net;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
using Android.Widget;
namespace smartapp
{
[Activity(Label = "PageActivity")]
public class PageActivity : Activity
{
ListView listv;
ArrayAdapter adapter;
ArrayList Plays;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Pages);
getData();
listv = FindViewById<ListView>(Resource.Id.listv);
adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, Plays);
listv.Adapter = adapter;
listv.FastScrollEnabled = true;
// Create your application here
listv.ItemClick+= (object sender,AdapterView.ItemClickEventArgs e)=>{
Intent myintent;
switch(Plays[e.Position])
{
case 0:
myintent=new Intent(this,typeof(HelpActivity));
StartActivity(myintent);
break;
case 1:
myintent=new Intent(this,typeof(IslamActivity));
StartActivity(myintent);
break;
case 2:
myintent=new Intent(this,typeof(AllPagesActivity));
StartActivity(myintent);
break;
}
};
}
private void getData()
{
Plays = new ArrayList();
Plays.Add("Care Center");
Plays.Add("Real Islam");
Plays.Add("All Pages");
}
}
}
Upvotes: 1
Views: 52
Reputation: 16419
The problem according to me is with your Switch it should be something like this:
switch(e.Position)
{
case 0:
myintent=new Intent(this,typeof(HelpActivity));
StartActivity(myintent);
break;
case 1:
myintent=new Intent(this,typeof(IslamActivity));
StartActivity(myintent);
break;
case 2:
myintent=new Intent(this,typeof(AllPagesActivity));
StartActivity(myintent);
break;
}
Upvotes: 1