基于Button Click的具有多个嵌套活动的TabActivity



我面临的问题是如何在嵌套的选项卡活动中导航基于Android点击按钮的活动。

我有3个选项卡"仪表板"、"车辆搜索"one_answers"位置搜索"。当我按位置搜索选项卡我得到一个编辑文本(输入邮政编码(然后按按钮(当我按下它时,我应该能找到100英里内的位置不同页面中的邮政编码称为位置搜索结果页面(

我的具体问题是,当我按下"开始"按钮时,应用程序崩溃在我得到的位置之前

我有MainActivity类,它扩展了TabActivity并定义了所有标签

public class MainActivity extends TabActivity
{
     public TabHost tabHost;
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       tabHost = (TabHost) findViewById(android.R.id.tabhost);
       TabHost.TabSpec spec;
       Intent intent;
       intent = new Intent().setClass(this, DashBoard.class);
       spec =
tabHost.newTabSpec("dashboard").setIndicator("DashBoard").setContent(intent);
       tabHost.addTab(spec);
       intent = new Intent().setClass(this, VehicleSearch.class);
       spec =
tabHost.newTabSpec("vehicleSearch").setIndicator("VehicleSearch").setContent(intent);
       tabHost.addTab(spec);
       intent = new Intent().setClass(this, BranchSearch.class);
       spec =
tabHost.newTabSpec("branchSearch").setIndicator("BranchSearch").setContent(intent);
       tabHost.addTab(spec);
       tabHost.setCurrentTab(3);
}

我还有BranchSearchHelper类,它扩展了ActivityGroup

public class BranchSearchHelper extends ActivityGroup
{
     public static BranchSearchHelper branchSearch;
     private ArrayList<View> history;
     @Override
   public void onCreate(Bundle savedInstanceState)
     {
       super.onCreate(savedInstanceState);
       branchSearch = this;
       this.history = new ArrayList<View>();

       View view =
getLocalActivityManager().startActivity("BranchSearch", new
Intent(this,BranchSearch.class)
                 .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
       replaceView(view);
     }
     public void replaceView(View v)
     {
                          // Adds the old one to history
                   history.add(v);
                           // Changes this Groups View to the new
View.
                   setContentView(v);
     }
      public void back()
      {
                    if(history.size() > 0) {
                        history.remove(history.size()-1);
setContentView(history.get(history.size()-1));
                    }
                    else
                    {
                        finish();
                    }
}
               @Override
               public void onBackPressed()
               {
                 BranchSearchHelper.branchSearch.back();
                    return;
                }
}

BranchSearch类扩展了活动

public class BranchSearch extends Activity implements OnClickListener
{
     public void onCreate(Bundle savedInstanceState)
     {
             super.onCreate(savedInstanceState);
             setContentView(R.layout.branchsearch);
             Button locSearch = (Button)
findViewById(R.id.btnlocSearch);
             locSearch.setOnClickListener(this);
         }
      public void onClick(View v)
     {
                 // TODO Auto-generated method stub
                 EditText editText = (EditText)
findViewById(R.id.lsearch);
                 Bundle bundle = new Bundle();
                 bundle.putString("zipCode",
editText.getText().toString() );
                 Intent i = new Intent(getApplicationContext(),
LocationSearchResults.class);
                 i.putExtras(bundle);
                 i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                View view =
BranchSearchHelper.branchSearch.getLocalActivityManager().startActivity("Locations
Results",i).getDecorView();
                 BranchSearchHelper.branchSearch.replaceView(view);
           }
}

我总是得到异常向抛出的javaNUllPointerexception

View view =
BranchSearchHelper.branchSearch.getLocalActivityManager().startActivity("Locations
Results",i).getDecorView();

因为branchSearch为空

你能告诉我如何跟踪标签并显示吗当我按下go按钮时,所有的定位结果使应用程序崩溃。(我应该更改代码的哪些部分(

有一个名为LocationSearchResults的类,它处理显示所有位置搜索结果

branchSearch = this;将使branchSearch成为ActivityGroup。要更正此问题,可以删除此问题,并在onClick声明的底部添加行branchSearch = view;

最新更新