我有一个Android应用程序,当用户登录时,员工ID从一个活动转移到另一个活动。这通常很好,但是当我使用tab控件进行这两个活动时。员工ID不会从一个活动转到另一个活动。 请告诉我在选项卡控件类中出错的地方。我需要在哪里调用函数将值从制表符控件转移到下一个类
我从登录界面发送数据的功能是
resp = new JSONObject(result);
JSONObject Login1Result = resp.getJSONObject("LoginResult");
String strMessage = Login1Result.getString("EmployeeID");
Intent i = new Intent(getApplicationContext(), TabControl.class);
i.putExtra("new_variable_name",strMessage);
startActivity(i);
我通过
将其称为我的下两个课程{
Bundle extras = getIntent().getExtras();
String strEmployeeID="";
if (extras != null)
{
String value = extras.getString("new_variable_name");
strEmployeeID = value;
}
Intent i = new Intent(getApplicationContext(), MYCLASS.class);
i.putExtra("new_variable_name",strEmployeeID);
startActivity(i);
}
,我的标签控件类
public class TabControl extends TabActivity
{
public static TabControl mTabControl;
public static TextView textView;
public static TabHost tabHost ;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Resources ressources = getResources();
TabHost tabHost = getTabHost();
// Android tab
Intent intentAndroid = new Intent().setClass(this, HourlyEntry.class);
TabSpec tabSpecAndroid = tabHost
.newTabSpec("Hourly Entry")
.setIndicator("", ressources.getDrawable(R.drawable.tab_home))
.setContent(intentAndroid);
// Apple tab
Intent intentApple = new Intent().setClass(this, LeaveApp.class);
TabSpec tabSpecApple = tabHost
.newTabSpec("Leave Application")
.setIndicator("", ressources.getDrawable(R.drawable.tab_giveaward))
.setContent(intentApple);
tabHost.addTab(tabSpecAndroid);
tabHost.addTab(tabSpecApple);
//set Windows tab as default (zero based)
tabHost.setCurrentTab(0);
}
}
我使用员工ID的微调器
public void addItemsOnSpinner1()
{
Bundle extras = getIntent().getExtras();
String strEmployeeID="";
if (extras != null) {
String value = extras.getString("new_variable_name");
// Toast.makeText(getBaseContext(), value, Toast.LENGTH_LONG).show();
strEmployeeID = value;
}
JSONObject login = new JSONObject();
try
{
login.put("EmployeeID",strEmployeeID);
//login.put("Password", etCountry.getText().toString());
JSONObject finaldata = new JSONObject();
finaldata.put("ProjectRequest", login);
答案 0 :(得分:2)
当您从Intent
获取数据时,您正在Bundle
传递数据。
这是唯一的问题。
尝试以下代码。
// To get Data in Tab control class
strEmployeeID = getIntent().getStringExtra("new_variable_name");
更新代码:
// declare at the top in TabControl class
public static String strEmployeeID = "";
答案 1 :(得分:1)
尝试做这样的事情
Bundle extras = getIntent().getExtras();
String strEmployeeID="";
TabSpec photospec = tabHost.newTabSpec("Hourly");
// setting Title and Icon for the Tab
photospec.setIndicator("Hourly Entry");
if (extras != null)
{
String value = extras.getString("new_variable_name");
// Toast.makeText(getBaseContext(), value, Toast.LENGTH_LONG).show();
strEmployeeID = value;
}
Intent photosIntent = new Intent(getApplicationContext(), HourlyEntry.class);
photosIntent.putExtra("new_variable_name",strEmployeeID);
photospec.setContent(photosIntent);