2013-05-08 34 views
0

我有內部RelativeLayouts一個RelativeLayout的,機器人隱藏內心的RelativeLayout防止活動出現

我需要隱藏它取決於一些邏輯裏面一些RelativeLayouts,

的問題是,如果我隱藏任何的我內心的RelativeLayouts,活動doesent出現,

我有checked this page做我在做什麼,但我的工作?

這裏我的代碼,

XML爲活動

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/warning_bgnd" 
    android:orientation="vertical" > 

<Button 
    android:id="@+id/button_warning" 
    style="@style/okWarningButton" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="62dp" /> 

<RelativeLayout 
    android:id="@+id/layout_warningA" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="70dp"> 

    <ImageView 
     android:id="@+id/imageViewA" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/button_warning" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="18dp" 
     android:layout_marginTop="10dp" 
     android:src="@drawable/warning_red" 
     tools:ignore="ContentDescription" /> 

    <TextView 
     android:id="@+id/warningTitleA" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="70dip" 
     android:paddingTop="0px" 
     android:text="@string/textarea_warning_title" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#ffffff" /> 

    <TextView 
     android:id="@+id/warningMessageA" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/warningTitleA" 
     android:layout_marginTop="4dp" 
     android:paddingLeft="70dip" 
     android:text="@string/textarea_warning_cat_a" 
     android:textColor="#B5B5B5" 
     android:textSize="12sp" /> 
</RelativeLayout> 


    <RelativeLayout 
    android:id="@+id/layout_warningB" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="170dp"> 

    <ImageView 
     android:id="@+id/imageViewB" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/button_warning" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="18dp" 
     android:layout_marginTop="10dp" 
     android:src="@drawable/warning_orange" 
     tools:ignore="ContentDescription" /> 

    <TextView 
     android:id="@+id/warningTitleB" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="70dip" 
     android:paddingTop="0px" 
     android:text="@string/textarea_warning_title" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#ffffff" /> 

    <TextView 
     android:id="@+id/warningMessageB" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/warningTitleB" 
     android:layout_marginTop="4dp" 
     android:paddingLeft="70dip" 
     android:text="@string/textarea_warning_cat_b" 
     android:textColor="#B5B5B5" 
     android:textSize="12sp" /> 
</RelativeLayout> 

    <RelativeLayout 
    android:id="@+id/layout_warningC" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="275dp"> 

    <ImageView 
     android:id="@+id/imageViewC" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/button_warning" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="18dp" 
     android:layout_marginTop="10dp" 
     android:src="@drawable/warning_green" 
     tools:ignore="ContentDescription" /> 

    <TextView 
     android:id="@+id/warningTitleC" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="70dip" 
     android:paddingTop="0px" 
     android:text="@string/textarea_warning_title" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#ffffff" /> 

    <TextView 
     android:id="@+id/warningMessageC" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/warningTitleC" 
     android:layout_marginTop="4dp" 
     android:paddingLeft="70dip" 
     android:text="@string/textarea_warning_cat_c" 
     android:textColor="#B5B5B5" 
     android:textSize="12sp" /> 
    </RelativeLayout> 

</RelativeLayout> 

並在Java文件中的代碼

public class WarningActivity extends PrestartAbstractActivity { 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_warning); 

    //myWarningLayouts 
    RelativeLayout layoutA = (RelativeLayout)this.findViewById(R.id.layout_warningA); 
    RelativeLayout layoutB = (RelativeLayout)this.findViewById(R.id.layout_warningB); 
    RelativeLayout layoutC = (RelativeLayout)this.findViewById(R.id.layout_warningC); 




    //retrieve data for intent 
    Intent intent = getIntent(); 
    String warningType = intent.getStringExtra("type"); 


    Log.d("mensa", "me entro en warning ::"+warningType); 


    //TODO, IMAGE BUTTON!! 

    Button newPreStartButton = (Button) findViewById(R.id.button_warning); 
    newPreStartButton.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      restartForms(); 
     } 
    }) ; 


    //manage warning type 

    int warningTypeInt = Integer.valueOf(warningType.toString()); 


    switch (warningTypeInt) { 
    case 0: 
     Log.d("mensa", "never happens"); 
     break; 
    case 1: 
     Log.d("mensa", "case 1"); 

     layoutA.setVisibility(View.VISIBLE); 
     layoutB.setVisibility(View.INVISIBLE); 
     layoutC.setVisibility(View.INVISIBLE); 

     break; 
    case 2: 
     Log.d("mensa", "case 2"); 
     break; 
    case 3: 
     Log.d("mensa", "case 3"); 
     break; 
    case 4: 
     Log.d("mensa", "case 4"); 
     break; 
    case 5: 
     Log.d("mensa", "case 5"); 
     break; 
    case 6: 
     Log.d("mensa", "case 6"); 
     break; 
    case 7: 
     Log.d("mensa", "case 7"); 

     break; 
    default: 
    Log.d("mensa", "default switch"); 
    } 

} 

所以,在我的測試,如果我有情況1, 永遠不會被調用,甚至不能看到活動的內部日誌?

什麼是缺少隱藏我的內部佈局?

謝謝!

+0

應該有相對佈局兩個關閉的標籤。是在文章中留下的錯誤還是代碼的確切副本? – 2013-05-08 04:11:10

+0

嗨@AnirudhaAgashe謝謝,現在編輯 – MaKo 2013-05-08 04:20:59

+0

對於我來說,上面的XML和代碼工作正常,因爲你期待它的工作...如果我給1而不是warningTypeInt內開關情況下只有第一個相對佈局是可見的。問題是與warningTypeInt檢查它正在檢索什麼值.. – Zombie 2013-05-08 05:00:54

回答

1

您尚未定義該按鈕的layout_width和layout_height。檢查logcat應該給出某種錯誤。此代碼在向按鈕提供寬度和高度並提供一些文本或圖像以在按鈕上顯示時起作用。你可以做到這一點的

android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="@string/warningBtnText" 
在XML底部
+0

嗨,謝謝我已經修復了這一點,但不幸的是不能解決我的問題,它可能是什麼? – MaKo 2013-05-08 04:34:40

+0

你可以發佈日誌cat輸出嗎?另一件事是在創建warningTypeInt的時候你可能會得到一個異常。在解析之前使用日誌檢查warningType的值。 – 2013-05-08 04:38:43