2012-03-20 109 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