0

我将 ListNavigation 和 Sharing 小部件添加到 ActionBar。但我认为我做得不太正确,它会导致屏幕不断刷新。

这是我所做的:

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTheme(R.style.Theme_Sherlock_Light);
    ...

以下是支持这两个动作的方法。我认为它们在某种程度上发生了冲突,但我不确定如何将它们结合起来。

@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) 
{        
    if ( itemPosition == 0 )
    {
        Intent myIntent = new Intent(MainActivity.this, MainActivity.class);
        MainActivity.this.startActivity(myIntent);          
    }
    else
    if ( itemPosition == 1 )
    {
        Intent myIntent = new Intent(MainActivity.this, LearnActivity.class);
        MainActivity.this.startActivity(myIntent);          
    }        
    else
    if ( itemPosition == 2 )
    {
        Intent myIntent = new Intent(MainActivity.this, ServicesActivity.class);
        MainActivity.this.startActivity(myIntent);          
    }        
    else
    if ( itemPosition == 3 )
    {
        Intent myIntent = new Intent(MainActivity.this, GiveBackActivity.class);
        MainActivity.this.startActivity(myIntent);
    }                

    return true;
}    



@Override
public boolean onCreateOptionsMenu(Menu menu) 
{
    // Inflate your menu.       
    getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);

    // Set file with share history to the provider and set the share intent.
    MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();        

    // Note that you can set/change the intent any time,
    // say when the user has selected an image.
    actionProvider.setShareIntent(createShareIntent());

    return true;
}    


/**
 * Creates a sharing {@link Intent}.
 *
 * @return The sharing intent.
 */
private Intent createShareIntent() 
{   
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");

    shareIntent.putExtra(Intent.EXTRA_TEXT,"TestText");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "TestSubject");

    return shareIntent;
}    

有人知道如何解决这个问题吗?谢谢!

4

0 回答 0