2013-03-21 3 views
1

5 개의 탭이있는 응용 프로그램을 개발 중이며 마지막 탭에 메뉴 목록이 표시됩니다. 메뉴 탭을 클릭하면 메뉴 탭이 잘 보이지 않지만 메뉴 (LoginActivity를 호출합니다) 중 하나를 클릭하면 탭 아래에 새로운 활동이 전체 화면으로 표시됩니다. 어떻게 처리 할 수 ​​있습니까? 아래는 제 코드입니다.탭 외부에서 작업 호출

TabActivity

package com.smartag.smarttreasure; 
public class NfcSurveyActivity extends TabActivity { 


    @Override 
    protected void onResume() { 
     // TODO Auto-generated method stub 
     super.onResume(); 

     mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, 
       mTechLists); 

     int profileCount = db.getContactsCount(); 
     if (profileCount <= 0) { 
      Intent intent = new Intent(getApplicationContext(), 
        LoginActivity.class); 
      startActivity(intent); 
     } 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     int profileCount = db.getContactsCount(); 
     if (profileCount <= 0) { 
      Intent intent1 = new Intent(getApplicationContext(), 
        LoginActivity.class); 
      startActivity(intent1); 
     } 

     Bundle extras = getIntent().getExtras(); 
     if (extras != null) { 
      tabToDisplay = extras.getString("tab"); 
      if (tabToDisplay.equals("CAMERA")) { 
       barcodeData = extras.getString("barcodeData"); 
      } 
      extras.clear(); 
     } 

     TabHost tabHost = getTabHost(); 

     // Home 
     TabSpec tbspecHome = tabHost.newTabSpec("Home"); 
     tbspecHome.setIndicator("", 
       getResources().getDrawable(R.drawable.tab_account_style)); 

     Intent iHome = new Intent(this, HomeActivity.class); 
     tbspecHome.setContent(iHome); 
     tabHost.addTab(tbspecHome); 

     // History 
     tabHost.addTab(tabHost 
       .newTabSpec("Fun") 
       .setIndicator("", 
         getResources().getDrawable(R.drawable.tab_fun_style)) 
       .setContent(
         new Intent(this, NfcSurveyActivity.class) 
           .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); 

     if (tabToDisplay != null && tabToDisplay.equals("REDEEM")) { 
      if (barcodeData != null && barcodeData.length() > 0) { 

       tabHost.addTab(tabHost 
         .newTabSpec("Camera") 
         .setIndicator(
           "", 
           getResources().getDrawable(
             R.drawable.tab_redeem_style)) 
         .setContent(
           new Intent(this, NfcSurveyActivity.class) 
             .addFlags(
               Intent.FLAG_ACTIVITY_CLEAR_TOP) 
             .putExtra("autoLoadBarcodeData", 
               barcodeData))); 

      } 

      else { 
       tabHost.addTab(tabHost 
         .newTabSpec("Camera") 
         .setIndicator(
           "", 
           getResources().getDrawable(
             R.drawable.tab_redeem_style)) 
         .setContent(
           new Intent(this, NfcSurveyActivity.class) 
             .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); 

      } 

     } else { 
      tabHost.addTab(tabHost 
        .newTabSpec("Camera") 
        .setIndicator(
          "", 
          getResources().getDrawable(
            R.drawable.tab_redeem_style)) 
        .setContent(
          new Intent(this, NfcSurveyActivity.class) 
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); 
     } 

     // tabHost.setCurrentTab(2); 

     tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = tabHost 
       .getTabWidget().getChildAt(2).getLayoutParams().height + 19; 

     // Search 
     TabSpec tbspecSearch = tabHost.newTabSpec("Finder"); 
     tbspecSearch.setIndicator("", 
       getResources().getDrawable(R.drawable.tab_finder_style)); 

     Intent iSearch = new Intent(this, NfcSurveyActivity.class); 
     tbspecSearch.setContent(iSearch); 
     tabHost.addTab(tbspecSearch); 

     // Profile 
     TabSpec tbspecProfile = tabHost.newTabSpec("Quit"); 
     tbspecProfile.setIndicator("", 
       getResources().getDrawable(R.drawable.tab_quit_style)); 

     Intent iProfile = new Intent(this, NfcSurveyActivity.class); 
     tbspecProfile.setContent(iProfile); 

     tabHost.addTab(tbspecProfile); 

     for (int i = 0; i <= 4; i++) { 
      tabHost.getTabWidget() 
        .getChildTabViewAt(i) 
        .setBackgroundColor(
          getResources() 
            .getColor(android.R.color.transparent)); 

      if (i == 2) { 
       tabHost.getTabWidget() 
         .getChildTabViewAt(i) 
         .setPadding(
           tabHost.getTabWidget().getChildTabViewAt(i) 
             .getPaddingLeft(), 
           tabHost.getTabWidget().getChildTabViewAt(i) 
             .getPaddingTop(), 
           tabHost.getTabWidget().getChildTabViewAt(i) 
             .getPaddingRight(), 20); 
      } 

     } 

     if (tabToDisplay != null && tabToDisplay.length() > 0) { 
      if (tabToDisplay.equals("CAMERA")) { 
       tabHost.setCurrentTab(2); 

      } else if (tabToDisplay.equals("HISTORY")) { 
       tabHost.setCurrentTab(1); 

      } 

     } 

     tabHost.setOnTabChangedListener(new OnTabChangeListener() { 
      public void onTabChanged(String tabId) { 
       NfcSurveyConfiguration.SelectedTab = tabId; 
      } 
     }); 
    } 

} 

MenuActivity

public class HomeActivity extends ListActivity { 

    static final String[] Account = new String[] { "Point History", "Scan History", 
      "Reward/Coupon History", "Share/Transfer History", "Personalise" }; 
    String tabToDisplay = ""; 
    String barcodeData = ""; 
    SharedPreferences nfcSurveyConfiguration; 
    String profileId; 

    String pleaseWait = ""; 
    protected boolean _taken; 
    protected File _directory; 
    protected String _filename; 
    protected String _fileExtension; 


    String profileName = ""; 
    String profileEmail = ""; 
    String profileStatus = ""; 
    String profileLanguage = ""; 
    String profileType = ""; 
    DatabaseHandler db = new DatabaseHandler(this); 



    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setListAdapter(new ArrayAdapter<String>(this, 
       R.layout.listview_item_row, Account)); 

     ListView listView = getListView(); 

     listView.setTextFilterEnabled(true); 

     listView.setOnItemClickListener(new OnItemClickListener() { 
      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 
       // When clicked, show a toast with the TextView text 
       //Toast.makeText(getApplicationContext(), 
        // ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); 
       Intent intent1 = new Intent(getApplicationContext(), 
         LoginActivity.class); 
       startActivity(intent1); // This activity appears not in the tab    
      } 
     }); 


    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     NfcSurveyConfiguration.CurrentActiveTab = 0; 
    } 

} 

어떤 제안이나 조언은 높게 평가된다.

답변

0

이 코드는 setOnItemClickListener 내에있어이 문제를 해결하는 데 도움이됩니다.

View view1 = getLocalActivityManager().startActivity(
          "ReferenceName", 
          new Intent(getApplicationContext(), 
            YourActivityClass.class) 
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) 
          .getDecorView(); 
        setContentView(view1); 
관련 문제