2016-06-28 6 views
1

C#を使用してAndroidアプリケーションを作成しようとしています。 listviewasmxウェブサービスを使用してください。Java.Lang.RuntimeException:あなたのコンテンツには、C#xamarinのid属性が 'android.R.id.list'であるListViewが必要です。

は、ここで私は単にリストビュー内のデータをバインドしようとしています私のコード - 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> 

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"; 
     } 
    } 
} 

です。あなたのコンテンツは、ID属性「android.R.id.list」

すべてのヘルプはあるだろうListViewコントロールを持っている必要があります。

Java.Lang.RuntimeException - しかし、私はSetContentViewでエラーOnCreateを取得します感謝。ありがとう!

答えて

2

一覧活動@androidとリストが含まれている必要があります:あなたのリストビューidは

<ListView 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@android:id/list" /> 
+0

変更ID /リストおかげで、これは ' "@android:ID /リスト" を持つアンドロイドidは意味' 'simplellistitem'を特定する必要があります'ListAdapter'にあります。 – Priya

+1

ListActivityを使用している場合のみ –

関連する問題