0

如何從我的sherlock ActionBar項目導航菜單啓動任何活動? 這是我的代碼(我已經試過用烤麪包和現在的功能)。我如何從我的sherlock ActionBar項目開始一個活動?

public class MainActivity extends SherlockActivity implements OnNavigationListener { 

private String[] pasti; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    pasti = getResources().getStringArray(R.array.Pasti); 

    Context context = getSupportActionBar().getThemedContext(); 
    ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(context, R.array.Pasti, R.layout.sherlock_spinner_item); 
    list.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); 
    getSupportActionBar().setSubtitle("The Subtitle"); 

    getSupportActionBar().setDisplayShowTitleEnabled(true); 

    getSupportActionBar().setDisplayShowCustomEnabled(false); 

    getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 
    getSupportActionBar().setListNavigationCallbacks(list, this); 

    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 

    getSupportActionBar().setDisplayUseLogoEnabled(true); 

    getSupportActionBar().setDisplayShowHomeEnabled(true); 
} 
@Override 
    public boolean onNavigationItemSelected(int itemPosition, long itemId) { 
    Toast toast=Toast.makeText(this,"Selected: " + pasti[itemPosition],Toast.LENGTH_LONG); 
     toast.show(); 
     return true; 
    } 

} 

` 請幫助。感謝

回答

1

我已經解決了這個代碼:

switch (itemPosition) { 
     case 1: 
      Intent primi = new Intent(); 
      primi.setClass(getApplicationContext(), PrimiPiatti.class); 
      startActivity(primi); 
      break; 
     case 2: 
      break; 
     case 3: 
      break; 

     } 
     // return super.onOptionsItemSelected(itemPosition); 
     return true; 
    } 
}; 
getSupportActionBar().setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener); 

}

@Override 
public boolean onNavigationItemSelected(int itemPosition, long itemId) { 
    // TODO Auto-generated method stub 
    return false; 
} 
相關問題