我有一个Tabbed Activity,我想传递一个意图。我试图传递一些参数,这不是传递意图。我在onClickListener中设置当前Tab。我的代码如下,我该怎么做?
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("InlinedApi")
private void displayEvacRouteTable(){
AsyncClass ac = new AsyncClass(EvacRouteTableActivity.this);
ac.execute();
List<String> evacRouteList = new ArrayList<String>(DALController.sharedInstance().getAllRouteNames());
// get a reference for the TableLayout
TableLayout ll = (TableLayout) findViewById(R.id.TableLayout01);
for (String routeName : evacRouteList){
// create a new TableRow
TableRow row = new TableRow(this);
// create a new TextView
TextView destNameTextView = new TextView(this);
String evacRouteName = " " + routeName;
SpannableString evacRouteSpanString = new SpannableString(evacRouteName);
evacRouteSpanString.setSpan(new UnderlineSpan(), 0, evacRouteName.length(), 0);
destNameTextView.setText(evacRouteSpanString);
destNameTextView.setTextColor(Color.BLUE);
destNameTextView.setTextSize(20);
destNameTextView.setHeight(55);
Linkify.addLinks(evacRouteSpanString, Linkify.ALL);
final Intent i = new Intent(EvacRouteTableActivity.this, MapViewActivity.class);
Bundle b = new Bundle();
b.putString("evacObject", routeName);
i.putExtras(b);
destNameTextView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AsyncClass ac = new AsyncClass(EvacRouteTableActivity.this);
ac.execute();
@SuppressWarnings("deprecation")
TabActivity ta = (TabActivity) EvacRouteTableActivity.this.getParent();
ta.getTabHost().setCurrentTab(4);
}
});
destNameTextView.setBackgroundResource(R.drawable.cell_shape);
destNameTextView.setLayoutParams(new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
row.addView(destNameTextView);
ll.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
}
以下是我尝试用来接收意图的代码:
String fuelStopBundle = getIntent().getExtras();
if (fuelStopBundle != null){
evacName = fuelStopBundle.getString("evacObject");
答案 0 :(得分:0)
这可能会对你有所帮助,而不是通过意图使用静态变量传递字符串,
你的传球课
class EvacRouteTableActivity extends TabActivity{
public static String routeName="";
/**** write your code here****/
/****change the value of routeName string as per your desire****/
}
你的接收班,
class MapViewActivity extends Activity{
/**** write your code here****/
//access routeName string as below
String recieved_string= EvacRouteTableActivity.routeName;
}
如果您对此有任何疑问,请告诉我。