私は4つのアクティビティを持っています。値をTABアクティビティに移す
最初のアクティビティはデータ入力に使用され、2番目のアクティビティはTABメインアクティビティ(拡張TabActivity)で各タブアクティビティが宣言され、3番目と4番目のアクティビティはタブアクティビティです。
最初のアクティビティから3番目と4番目のアクティビティに値を転送するにはどうすればよいですか?
は、ここに私の第一の活動です:
public class FirstActivity extends Activity {
EditText inputName;
EditText inputAddress;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//declaration layout
inputName = (EditText) findViewById(R.id.editText1);
inputAddress = (EditText) findViewById(R.id.editText2);
Button btnNextScreen = (Button) findViewById(R.id.button1);
//Listening to button event
btnNextScreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
//Starting a new Intent
Intent nextScreen = new Intent(getApplicationContext(), MainTabActivity.class);
//Sending data to another Activity
//THIS IS THE VALUE I WANNA TRANSFER TO TAB ACTIVITY
nextScreen.putExtra("name", inputName.getText().toString());
nextScreen.putExtra("address", inputEmail.getText().toString());
// starting new activity
startActivity(nextScreen);
}
});
}
}
とここに私のMainTabActivityです:
public class MainTabActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maintabresto);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, InfoTab.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("info").setIndicator("Info",
res.getDrawable(R.drawable.iconinfotab))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, MenuTab.class);
spec = tabHost.newTabSpec("menu").setIndicator("Menu",
res.getDrawable(R.drawable.iconmenutab))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
、ここで私の第三第四の活動です(私はそれぞれの活動でのTextViewする前に転送する値を表示したいです):
public class InfoTab extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.infotab);
TextView txtname = (TextView) findViewById(R.id.textTEST1);
TextView txtaddress = (TextView) findViewById(R.id.TextTEST2);
//displaying data from previous activity
//this is didnt work
Intent i = getIntent();
// Receiving the Data
String name = i.getStringExtra("name");
String address = i.getStringExtra("address");
// Displaying Received data
//this is didnt work
txtname.setText(name);
txtaddress.setText(address);
}
}
誰でも私を助けることができますか? 私はfirts活動にこれを実行しようとしました:
Intent nextScreen = new Intent(getApplicationContext(), InfoTab.class);
それが動作する(値がnextactivityに転送、代わりにタブのアクティビティを開いて、活動は(ないタブに個別に開くことができます)。..! 。
はので、ここで私の目標は、各タブの活動に値を転送することであるAN彼らはMainTabActivityの下に開いている。
申し訳ありませんが、私はいくつかの小さなミスではあると思うならば私の英語イマイチ良い。
誰でも私を助けることができますか? –
解決しましたか?私も問題に直面しています。 –