0

我有一个要传递意图的选项卡式活动。我正在尝试传递一些参数,但这并没有传递意图。我在 onClickListener 中设置当前选项卡。我的代码在下面我该怎么做?

@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");
4

1 回答 1

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;

        }

如果您对此有任何问题,请告诉我。

于 2013-06-27T14:26:39.527 回答