我有一个 Android 应用程序,当用户登录时,员工 ID 从一个 Activity 转移到另一个 Activity 。这通常工作正常,但是当我对这两个 Activity 使用选项卡控件时。员工 ID 不会从一项 Activity 转到另一项 Activity 。 请告诉我在选项卡控件类中哪里出错了。我需要在哪里调用将值从选项卡控件传递到下一个类的函数
我从登录屏幕发送数据的函数是
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);
最佳答案
当您从 Bundle
获取数据时,您正在 Intent
中传递数据。
这是唯一的问题。
尝试以下代码。
// To get Data in Tab control class
strEmployeeID = getIntent().getStringExtra("new_variable_name");
更新代码:
// declare at the top in TabControl class
public static String strEmployeeID = "";
关于android - 选项卡控件类未从登录屏幕获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23005878/