2017-11-14 4 views
0

Aus irgendeinem Grund werden einige meiner Ansichtselemente nicht ausgeblendet, wenn ich die Sichtbarkeit auf Gone festlege, andere werden nicht angezeigt, wenn ich sie auf Visible setze.Einige Ansichtselemente werden nicht ausgeblendet, einige werden nicht angezeigt

In diesem Beispiel wird cmdCallMe nicht ausgeblendet und cmdOk und cmdCancel werden nicht angezeigt. Die anderen Elemente verhalten sich alle wie erwartet.

(Quelle leicht gekürzt)

Aktivitätscode:

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     SetContentView(Resource.Layout.p2); 
     titleStatusView = FindViewById<TextView>(Resource.Id.lblP2Status); 
     outputTextView = FindViewById<TextView>(Resource.Id.lblP2Timer); 
     lblConfirm = FindViewById<TextView>(Resource.Id.lblP2Confirm); 
     cmdP2Update = FindViewById<Button>(Resource.Id.cmdP2Update); 
     cmdP2Arrived = FindViewById<Button>(Resource.Id.cmdP2Arrived); 
     cmdP2SelfDeployed = FindViewById<Button>(Resource.Id.cmdP2SelfDeployed); 
     cmdP2CallMe = FindViewById<Button>(Resource.Id.cmdP2CallMe); 

     cmdOk = FindViewById<Button>(Resource.Id.cmdP2CallMe); 
     cmdCancel = FindViewById<Button>(Resource.Id.cmdP2CallMe); 

     // hide normal buttons 
     // these all hide as expected 
     cmdP2Update.Visibility = ViewStates.Gone; 
     cmdP2Arrived.Visibility = ViewStates.Gone; 
     cmdP2SelfDeployed.Visibility = ViewStates.Gone; 
     // this should hide cmdCallMe but it doesn't change 
     cmdP2CallMe.Visibility = ViewStates.Gone; 
     // show confirm elements 
     // this appears as expected 
     lblConfirm.Visibility = ViewStates.Visible; 
     // the following 2 buttons should appear, but don't 
     cmdOk.Visibility = ViewStates.Visible; 
     cmdCancel.Visibility = ViewStates.Visible; 

AXML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
     android:text="Status: EN-ROUTE" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lblP2Status" 
     android:gravity="center" /> 
    <TextView 
     android:text="00:00:00" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lblP2Timer" 
     android:gravity="center" 
     android:layout_marginBottom="19.0dp" /> 
    <Button 
     android:text="Update" 
     android:layout_width="match_parent" 
     android:layout_height="64.5dp" 
     android:id="@+id/cmdP2Update" 
     android:layout_marginBottom="10.5dp" 
     android:background="@android:color/holo_green_dark" /> 
    <Button 
     android:text="ARRIVED" 
     android:layout_width="match_parent" 
     android:layout_height="64.5dp" 
     android:id="@+id/cmdP2Arrived" /> 
    <Button 
     android:text="SELF DEPLOYED" 
     android:layout_width="match_parent" 
     android:layout_height="64.5dp" 
     android:id="@+id/cmdP2SelfDeployed" 
     android:layout_marginBottom="10.5dp" /> 
    <Button 
     android:text="CALL ME" 
     android:layout_width="match_parent" 
     android:layout_height="64.5dp" 
     android:id="@+id/cmdP2CallMe" 
     android:layout_marginTop="0.0dp" /> 
    <TextView 
     android:text="Are you sure?" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/lblP2Confirm" 
     android:gravity="center" 
     android:layout_marginBottom="16.0dp" 
     android:visibility="gone" /> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:minWidth="25px" 
     android:minHeight="25px" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/linearLayout1"> 
     <Button 
      android:text="OK" 
      android:layout_width="190dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/cmdOk" 
      android:visibility="gone" /> 
     <Button 
      android:text="Cancel" 
      android:layout_width="190dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/cmdCancel" 
      android:visibility="gone" /> 
    </LinearLayout> 
</LinearLayout> 

Wenn ich alle Werte für Schritt durch zugewiesen, wie ich erwarten würde. Ich kann nicht herausfinden, warum die Sichtbarkeit der Elemente dies nicht immer widerspiegelt.

Antwort

1

Schauen Sie sich Ihr Code:

cmdP2CallMe = FindViewById<Button>(Resource.Id.cmdP2CallMe); 

    cmdOk = FindViewById<Button>(Resource.Id.cmdP2CallMe); <-- reference error here 
    cmdCancel = FindViewById<Button>(Resource.Id.cmdP2CallMe);<-- reference error here 

:)

+0

Was kann ich Ihnen sagen? Es war spät... ;) – CompanyDroneFromSector7G

Verwandte Themen