2016-07-17 10 views
0

ListView에 표시 할보기를 부 풀리는 ListView 어댑터가 있습니다. 내가 같이 findViewById (Resource.Id.ItemId)를 사용하여보기에서 항목의 일부를 얻을 때 디버거가 발생하고 오류가 말하는 :Xamarin이 Android 인플레이 트보기와 동기화되지 않은 리소스 ID를 생성했습니다.

"System.InvalidCastException : 'Android.Widget 유형의 인스턴스를 변환 할 수 없습니다. TableRow '를 입력하여'Android.Widget.TextView ' "을 입력하십시오.

내가 사용하는 리소스 ID가 TextView에 매핑되어야한다는 것을 알고 있습니다.

또한 일부 항목에는 값을 가져 오지 못하므로 항상 기본값을 표시하는 다른 문제가 있습니다. 코드 여기

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:minWidth="25px" 
    android:minHeight="25px" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/tripViewTableLayout" 
    android:showDividers="beginning"> 
    <TableRow 
     android:id="@+id/tripViewTableRow1" 
     android:layout_width="match_parent" 
     android:showDividers="none" 
     android:gravity="left"> 
     <TextView 
      android:text="Servive Level" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:id="@+id/tripViewServiceLevel" 
      android:textSize="10dp" 
      android:layout_column="0" 
      android:layout_gravity="left" 
      android:layout_weight="0.4" 
      android:maxEms="1" 
      android:lines="1" 
      android:editable="false" 
      android:singleLine="true" /> 
     <TextView 
      android:text="Package Type" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:id="@+id/tripViewPackageType" 
      android:textSize="10dp" 
      android:layout_gravity="left" 
      android:layout_weight="0.4" 
      android:maxEms="1" 
      android:lines="1" 
      android:editable="false" 
      android:singleLine="true" 
      android:layout_column="1" /> 
     <TextView 
      android:text="Weight" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:id="@+id/tripViewWeight" 
      android:textSize="10dp" 
      android:ellipsize="end" 
      android:gravity="left" 
      android:layout_gravity="left" 
      android:layout_weight="0.1" 
      android:maxEms="1" 
      android:lines="1" 
      android:editable="false" 
      android:singleLine="true" 
      android:layout_column="2" /> 
     <TextView 
      android:text="Due Time" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:id="@+id/tripViewDueTime" 
      android:textSize="10dp" 
      android:gravity="left" 
      android:editable="false" 
      android:lines="1" 
      android:ellipsize="end" 
      android:singleLine="true" 
      android:layout_gravity="left" 
      android:layout_weight="0.1" 
      android:includeFontPadding="false" 
      android:layout_width="match_parent" 
      android:maxEms="1" 
      android:layout_marginTop="3dp" 
      android:layout_column="3" /> 
    </TableRow> 
    <TableRow 
     android:id="@+id/tripViewTableRow2" 
     android:layout_width="match_parent" 
     android:minWidth="25px" 
     android:minHeight="25px"> 
     <ImageView 
      android:src="@drawable/orangebar" 
      android:layout_column="0" 
      android:id="@+id/tripViewImageBar" 
      android:layout_height="match_parent" 
      android:scaleType="fitStart" 
      android:cropToPadding="false" 
      android:layout_width="5dp" /> 
     <LinearLayout 
      android:orientation="vertical" 
      android:minWidth="25px" 
      android:minHeight="25px" 
      android:id="@+id/tripViewLinearLayout1" 
      android:layout_column="1" 
      android:layout_span="3" 
      android:layout_weight="1" 
      android:layout_gravity="left" 
      android:layout_width="match_parent"> 
      <TextView 
       android:text="Company" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:id="@+id/tripViewCompanyName" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textSize="15dp" 
       android:lines="1" 
       android:maxEms="1" 
       android:editable="false" /> 
      <TextView 
       android:text="Address" 
       android:textAppearance="?android:attr/textAppearanceSmall" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/tripViewCompanyAddress" 
       android:editable="false" 
       android:maxLines="1" /> 
     </LinearLayout> 
    </TableRow> 
</TableLayout> 

됩니다 : 여기

는 axml입니다

using System.Collections.Generic; 
using Android.App; 
using Android.Views; 
using Android.Widget; 
using RemoteService.Model; 

namespace Driod2.Trips 
{ 
    public class TripListAdapter : BaseAdapter<Trip> 
    { 
     private readonly List<Trip> Trips; 
     private readonly Activity Context; 

     public override long GetItemId(int position) { return position; } 

     public override View GetView(int position, View convertView, ViewGroup parent) 
     { 
      var T = Trips[ position ]; 

      var Row = convertView ?? Context.LayoutInflater.Inflate(Resource.Layout.TripListViewRow, null); // re-use an existing view, if one is available 

      Row.FindViewById<TextView>(Resource.Id.tripViewServiceLevel).Text = T.ServiceLevel; 
      Row.FindViewById<TextView>(Resource.Id.tripViewPackageType).Text = T.PackageType; 

      // !!!! The Error Happens here !!!!!! 
      Row.FindViewById<TextView>(Resource.Id.tripViewWeight).Text = T.Weight.ToString("F"); 


      // !!!! If I don't get the error the the next 4 never change !!!!!! 
      Row.FindViewById<TextView>(Resource.Id.tripViewDueTime).Text = T.DueTime.ToShortTimeString(); 
      Row.FindViewById<ImageView>(Resource.Id.tripViewImageBar).SetImageResource(Resource.Drawable.BlueBar); 
      Row.FindViewById<TextView>(Resource.Id.tripViewCompanyName).Text = T.DeliveryCompany; 
      Row.FindViewById<TextView>(Resource.Id.tripViewCompanyAddress).Text = T.DeliveryCompanyAddressId.ToString(); 

      return Row; 
     } 

     public override int Count => Trips.Count; 

     public override Trip this[ int position ] => Trips[ position ]; 

     public TripListAdapter(Activity context, List<Trip> trips) 
     { 
      Context = context; 
      Trips = trips; 
     } 
    } 
} 

그리고 자동 자원 생성 :

#pragma warning disable 1591 
//------------------------------------------------------------------------------ 
// <auto-generated> 
//  This code was generated by a tool. 
//  Runtime Version:4.0.30319.42000 
// 
//  Changes to this file may cause incorrect behavior and will be lost if 
//  the code is regenerated. 
// </auto-generated> 
//------------------------------------------------------------------------------ 

[assembly: global::Android.Runtime.ResourceDesignerAttribute("Driod2.Resource", IsApplication=true)] 

namespace Driod2 
{ 


    [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] 
    public partial class Resource 
    { 

     static Resource() 
     { 
      global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
     } 

     public static void UpdateIdValues() 
     { 
      global::IdsRemoteService.Resource.String.ApplicationName = global::Driod2.Resource.String.ApplicationName; 
      global::IdsRemoteService.Resource.String.Hello = global::Driod2.Resource.String.Hello; 
      global::RemoteService.Resource.String.ApplicationName = global::Driod2.Resource.String.ApplicationName; 
      global::RemoteService.Resource.String.Hello = global::Driod2.Resource.String.Hello; 
     } 

     public partial class Attribute 
     { 

      static Attribute() 
      { 
       global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
      } 

      private Attribute() 
      { 
      } 
     } 

     public partial class Color 
     { 

      // aapt resource value: 0x7f060000 
      public const int AliceBlue = 2131099648; 

      // aapt resource value: 0x7f060001 
      public const int SteelBlue = 2131099649; 

      static Color() 
      { 
       global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
      } 

      private Color() 
      { 
      } 
     } 

     public partial class Drawable 
     { 

      // aapt resource value: 0x7f020000 
      public const int BlueBar = 2130837504; 

      // aapt resource value: 0x7f020001 
      public const int BottomBorder = 2130837505; 

      // aapt resource value: 0x7f020002 
      public const int CaratDownWhite = 2130837506; 

      // aapt resource value: 0x7f020003 
      public const int CloudWhite = 2130837507; 

      // aapt resource value: 0x7f020004 
      public const int ForwardWhite = 2130837508; 

      // aapt resource value: 0x7f020005 
      public const int Icon = 2130837509; 

      // aapt resource value: 0x7f020006 
      public const int offline32x32 = 2130837510; 

      // aapt resource value: 0x7f020007 
      public const int online32x32 = 2130837511; 

      // aapt resource value: 0x7f020008 
      public const int OrangeBar = 2130837512; 

      static Drawable() 
      { 
       global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
      } 

      private Drawable() 
      { 
      } 
     } 

     public partial class Id 
     { 

      // aapt resource value: 0x7f07000c 
      public const int accountId = 2131165196; 

      // aapt resource value: 0x7f070003 
      public const int appTitle = 2131165187; 

      // aapt resource value: 0x7f070000 
      public const int baseLayout = 2131165184; 

      // aapt resource value: 0x7f07000a 
      public const int button1 = 2131165194; 

      // aapt resource value: 0x7f070014 
      public const int filter1Button = 2131165204; 

      // aapt resource value: 0x7f070015 
      public const int filter2Button = 2131165205; 

      // aapt resource value: 0x7f070016 
      public const int filter3Button = 2131165206; 

      // aapt resource value: 0x7f070001 
      public const int frameLayout1 = 2131165185; 

      // aapt resource value: 0x7f070002 
      public const int gridLayout1 = 2131165186; 

      // aapt resource value: 0x7f070005 
      public const int linearLayout2 = 2131165189; 

      // aapt resource value: 0x7f070013 
      public const int linearLayout3 = 2131165203; 

      // aapt resource value: 0x7f070008 
      public const int loginLayout = 2131165192; 

      // aapt resource value: 0x7f070007 
      public const int mainViewFlipper = 2131165191; 

      // aapt resource value: 0x7f070010 
      public const int password = 2131165200; 

      // aapt resource value: 0x7f070006 
      public const int pingIcon = 2131165190; 

      // aapt resource value: 0x7f070011 
      public const int signInButton = 2131165201; 

      // aapt resource value: 0x7f070009 
      public const int textView2 = 2131165193; 

      // aapt resource value: 0x7f07000b 
      public const int textView3 = 2131165195; 

      // aapt resource value: 0x7f07000d 
      public const int textView4 = 2131165197; 

      // aapt resource value: 0x7f07000f 
      public const int textView5 = 2131165199; 

      // aapt resource value: 0x7f070004 
      public const int tripCount = 2131165188; 

      // aapt resource value: 0x7f070012 
      public const int tripLayout = 2131165202; 

      // aapt resource value: 0x7f070017 
      public const int tripListView = 2131165207; 

      // aapt resource value: 0x7f070022 
      public const int tripViewCompanyAddress = 2131165218; 

      // aapt resource value: 0x7f070021 
      public const int tripViewCompanyName = 2131165217; 

      // aapt resource value: 0x7f07001d 
      public const int tripViewDueTime = 2131165213; 

      // aapt resource value: 0x7f07001f 
      public const int tripViewImageBar = 2131165215; 

      // aapt resource value: 0x7f070020 
      public const int tripViewLinearLayout1 = 2131165216; 

      // aapt resource value: 0x7f07001b 
      public const int tripViewPackageType = 2131165211; 

      // aapt resource value: 0x7f07001a 
      public const int tripViewServiceLevel = 2131165210; 

      // aapt resource value: 0x7f070018 
      public const int tripViewTableLayout = 2131165208; 

      // aapt resource value: 0x7f070019 
      public const int tripViewTableRow1 = 2131165209; 

      // aapt resource value: 0x7f07001e 
      public const int tripViewTableRow2 = 2131165214; 

      // aapt resource value: 0x7f07001c 
      public const int tripViewWeight = 2131165212; 

      // aapt resource value: 0x7f07000e 
      public const int userName = 2131165198; 

      static Id() 
      { 
       global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
      } 

      private Id() 
      { 
      } 
     } 

     public partial class Layout 
     { 

      // aapt resource value: 0x7f030000 
      public const int Main = 2130903040; 

      // aapt resource value: 0x7f030001 
      public const int TripListViewRow = 2130903041; 

      static Layout() 
      { 
       global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
      } 

      private Layout() 
      { 
      } 
     } 

     public partial class Raw 
     { 

      // aapt resource value: 0x7f040000 
      public const int BadScan = 2130968576; 

      // aapt resource value: 0x7f040001 
      public const int DeletedTrip = 2130968577; 

      // aapt resource value: 0x7f040002 
      public const int NewTrip = 2130968578; 

      static Raw() 
      { 
       global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
      } 

      private Raw() 
      { 
      } 
     } 

     public partial class String 
     { 

      // aapt resource value: 0x7f050001 
      public const int ApplicationName = 2131034113; 

      // aapt resource value: 0x7f050000 
      public const int Hello = 2131034112; 

      static String() 
      { 
       global::Android.Runtime.ResourceIdManager.UpdateIdValues(); 
      } 

      private String() 
      { 
      } 
     } 
    } 
} 
#pragma warning restore 1591 

누군가가 자동으로 생성 된 이유를 알고 있나요을 리소스가 Android의 확장 된보기와 동기화되지 않습니까?

+0

나는 바이러스처럼 앱을 통해 퍼지고 있습니다. 주 앱 레이아웃을 약간 변경 했는데도 주 작업을로드하는 데 비슷한 오류가 발생합니다. 마치 자동 생성 된 리소스가 변경 되더라도 Android의 리소스가 변경되지 않는 것입니다. – Terry151151

+0

Xamarin을 다시 설치하여 고정했습니다. – Terry151151

답변

0

확실치 않지만 잘못된보기를보고있을 수 있습니다.

var Row = convertView ?? Context.LayoutInflater.Inflate(Resource.Layout.TripListViewRow, null);

실제로, 당신에게 TableLayout을 포기하지 않을 중 하나 TableRow의의입니다. 실제 TableRow의를 얻으려면 다음 actualRow1actualRow2에 등 당신의 TextView의, 찾아

TableRow actualRow1 = Row.FindViewById<TableRow>(Resource.Id.tripViewTableRow1); 
TableRow actualRow2 = Row.FindViewById<TableRow>(Resource.Id.tripViewTableRow2); 

을 할 필요가 있습니다.

+0

문제가 여러 번 발생했는데 에뮬레이터에서 사용자 데이터를 지우면 문제가 해결 된 것 같습니다. – Terry151151