2012-03-20 120 views
0

在我的活動我有屏幕登錄的15%的部分,它是一個TextView和一個按鈕:刷新活動

<TextView    
     android:id="@+id/registered_text" 
     android:color = "@color/white" 
     android:layout_width="wrap_content" 
     android:textSize="20dip" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dip" 
     ></TextView> 

     <Button 
     style="@style/myButton" 
     android:id="@+id/reg_button" 
     android:layout_width="wrap_content"  
     android:layout_alignParentRight="true"  
     android:layout_marginRight="10dip" 
     android:layout_height="wrap_content" 
    > 
    </Button>  

TextView的價值和按鈕文本和偵聽取決於用戶是否註冊:

loginDB login = new loginDB(context); 
    Cursor cursor = login.logData(new String[]{"userJoomla", "idUSER", "name","email"}); 

    if (cursor.moveToFirst()) { 
     userJoomla = cursor.getInt(0); 
     userID = cursor.getInt(1); 
     name = cursor.getString(2); 
     email = cursor.getString(3); 

     greeting.setText("Hola " + name); 
     loginLogout.setText("Desconectarme"); 

     loginLogout.setOnClickListener(logout); 
    } else { 
     name = "usuario móvil"; 
     greeting.setText(""); 
     loginLogout.setText("Identificarme"); 
     loginLogout.setOnClickListener(newLogin); 
    } 

    login.close(); 

如何在用戶登錄或註銷時刷新它?

謝謝你提前

+0

你想刷新什麼用碎片?你想換掉整個屏幕嗎? – 2012-03-20 15:56:18

回答

0

我不知道你到底想做什麼。你只是想改變一個按鈕的文本或替換你的完整屏幕?

更改按鈕標題非常簡單。在你onClickListener做同樣的,你已經做了:

loginLogout.setText("some new text"); 

如果你想改變整個屏幕,你可以通過兩種方式在登錄/註銷反應。 您可以在登錄成功後開始一項新活動,並在註銷成功後完成當前活動

或者您使用分段。 (更好的方法)

Fragments是「或多或少」像活動中的活動一樣的東西。一個活動可以包含多個片段。您可以在運行時替換,添加和刪除碎片。多數民衆贊成你如何可以交換你的整個屏幕或只是其中的一部分。

使用Compatibility Library在設備上<蜂窩

+0

我不知道有關碎片,但他們正是我正在尋找的!謝謝! – user1256477 2012-03-20 16:53:01