2013-04-26 68 views
0

我想從這個活動如何從標籤活動通過意向

public class HomeActivity extends android.app.TabActivity 
{ 
    String uid; 
protected void onCreate(Bundle savedInstanceState) 
     { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 
    TabHost tabHost = getTabHost(); 
    Intent intent = getIntent(); 
    uid = intent.getStringExtra("uid"); 
    // Tab for ActivityOne 
    TabSpec photospec = tabHost.newTabSpec("Home"); 
    photospec.setIndicator("Home", getResources().getDrawable(R.drawable.one)); 
    Intent photosIntent = new Intent(this, TabhomeActivity.class); 
    photosIntent.putExtra("uid", uid); 
    // startActivityForResult(photosIntent,0); 
    photospec.setContent(photosIntent); 

    // Tab for ActivitySecond 
    TabSpec songspec = tabHost.newTabSpec("Today's Meeting"); 
    // setting Title and Icon for the Tab 
    songspec.setIndicator("Today's Meeting", 
              getResources().getDrawable(R.drawable.one)); 
    Intent songsIntent = new Intent(this,TodaysmeetingActivity.class); 
    songspec.setContent(songsIntent); 
    // Adding all TabSpec to TabHost 
    tabHost.addTab(photospec); // Adding photos tab 
    tabHost.addTab(songspec); // Adding songs tab 
    } 
} 

這一活動送超值值發送到活動..

public class TabhomeActivity extends Activity { 

Button button1; 
Button button2; 
Button button3; 
TextView txtview,shwname; 
String uid; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_tabhome); 
    Intent intent = getParent().getIntent(); 
    uid = intent.getStringExtra("uid"); 
    shwname=(TextView)findViewById(R.id.textView3); 
    shwname.setText("Hi\t"+uid); 
} 

誰能幫助我?請。提前致謝。

+0

究竟是不是工作?從該段落髮布LogCat plz – bofredo 2013-04-26 09:29:53

+0

我沒有得到我的TabHomeActivity的意圖值 – priya89 2013-04-26 09:44:47

回答

0

發送時:

Intent i = new Intent(); 
intent.putString("uid", uid); 

在接收時:

Intent intent = getIntent(); 
Bundle extras = intent.getExtras(); 
uid = getIntent().getExtras().getString("uid"); 

或(使用束):

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    savedInstanceState = getIntent().getExtras(); 
    uid = savedInstanceState.getString("uid"); 
} 
+1

越來越想diplay在文本視圖中,當一個空值時,得到一個空值我TabhomeActivity .. :( – priya89 2013-04-26 10:46:53

+0

什麼呢Log.i( 「UID」, 「UID =」 + UID);?在發送活動讓你 – bofredo 2013-04-26 10:50:18

+0

返回null值在日誌 – priya89 2013-04-26 11:02:34

0

嘗試以下。

Intent intent = getIntent(); 
Bundle extras = intent.getExtras(); 
uid = getIntent().getExtras().getString(YOUR_KEY); 

同樣的數據設置到意圖使用時

extras.putString(YOUR_KEY, YOUR_VALUE); 
+0

我得到一個空值。 :( – priya89 2013-04-26 10:08:21

+0

@ priya89當你保存你得到一個零和意圖獲取值這樣? – 2013-04-26 10:17:58

+0

試圖diplay在文本視圖中我TabhomeActivity – priya89 2013-04-26 10:47:38