我已經在Xamarin中實現了一個項目。在模擬器和設備上運行它時,它顯示不幸的是,應用程序已停止。Xamarin應用程序已停止
我是xamarin的新手,我對這個問題一無所知。 我已經解決了所有的錯誤和警告,但它只顯示那樣。
定製spinner.cs
namespace App1.Assets.Ccode.Cspinner
{
class CustomSpinner : BaseAdapter
{
private Context c;
private JavaList<CountryName> countries;
private LayoutInflater inflater;
public CustomSpinner(Context c, JavaList<CountryName> countries)
{
this.c = c;
this.countries = countries;
}
public override Java.Lang.Object GetItem(int position)
{
return countries.Get(position);
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
if (inflater == null)
{
inflater = (LayoutInflater)c.GetSystemService(Context.LayoutInflaterService);
}
if (convertView == null)
{
convertView = inflater.Inflate(Resource.Layout.country_list, parent, false);
}
TextView nameTxt = convertView.FindViewById<TextView>(Resource.Id.nameTxt);
ImageView img = convertView.FindViewById<ImageView>(Resource.Id.India);
//BIND
nameTxt.Text = countries[position].Name;
img.SetImageResource(countries[position].Image);
return convertView;
}
public override int Count
{
get
{
return countries.Size();
}
}
}
}
}
主要activiy
[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private Spinner sp;
private CustomSpinner adapter;
private JavaList<CountryName> countries;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
sp = FindViewById<Spinner>(Resource.Id.country);
countries = CountriesList.GetCountrys();
adapter = new CustomSpinner(this, countries);
sp.Adapter = (ISpinnerAdapter)adapter;
sp.ItemSelected += sp_ItemSelected;
}
void sp_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Toast.MakeText(this, countries[e.Position].Name, ToastLength.Short).Show();
}
}
}
清單文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="App1.App1" android:versionCode="1" android:versionName="1.0"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="App1"></application>
</manifest>
請保存我的一天,並幫助我在設備上運行它。
謝謝
什麼是目標框架? –
@Mohammed Dastagir你有**還沒有更新**有關'文件'的任何事情 – Mrinmoy
@Mrinmoy對不起,延遲。 –