1
我想制作一个使用C#
的android应用程序,我想在其中绑定一些数据listview
使用asmx
webservices。Java.Lang.RuntimeException:你的内容必须有一个ListView,其id属性是'android.R.id.list'in c#xamarin
这里是我的代码 -
MainActivity.cs
public class MainActivity : ListActivity
{
int count = 1;
EditText txtGRN;
EditText txtTcode;
TextView lblMessage;
Button Callservicebutton1;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate {
button.Text = string.Format ("{0} clicks!", count++);
};
Button renderpage = FindViewById<Button>(Resource.Id.RenderPage);
renderpage.Click += delegate {
StartActivity(typeof(RenderPage1));
};
txtGRN = FindViewById<EditText>(Resource.Id.txtGRN);
txtTcode = FindViewById<EditText>(Resource.Id.txtCode);
lblMessage = FindViewById<TextView>(Resource.Id.lblmessage);
Callservicebutton1 = FindViewById<Button>(Resource.Id.BtnServiceCall);
Callservicebutton1.Click += Callservicebutton1_Click;
}
private void Callservicebutton1_Click(object sender, EventArgs e)
{
ServiceUrl1.Service1 service1 = new ServiceUrl1.Service1();
ServiceUrlNew.AndriodService Objandrodservice = new ServiceUrlNew.AndriodService();
DataTable dt = new DataTable();
var data = Objandrodservice.GetBankDetails();
string[] items;
items = new string[] { Objandrodservice.GetBankDetails() };
ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, items);
ListView lstDisplayBankData = FindViewById<ListView>(Resource.Id.LstBankData);
}
private void Service_GetGrnVoucherStringCompleted(object sender, ServiceUrl.GetGrnVoucherStringCompletedEventArgs e)
{
Callservicebutton1.Enabled = true;
lblMessage.Text = "calling service";
}
}
}
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/myButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:text="Render Page"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/RenderPage" />
<EditText
android:text="GRN"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtGRN" />
<EditText
android:text="TCode"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtCode" />
<Button
android:text="Call Service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/BtnServiceCall" />
<TextView
android:text="View Message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lblmessage" />
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/LstBankData" />
</LinearLayout>
我只是想在列表视图中的数据绑定。但我得到一个错误OnCreate
在SetContentView
-
了java.lang.RuntimeException:你的内容必须有一个ListView其id属性为 'android.R.id.list'
任何帮助将是赞赏。谢谢 !
谢谢,这意味着'Android的ID “@android:ID /列表”'要找准'simplellistitem'在'ListAdapter'中。 – Priya
仅当您使用ListActivity时 –