我如何让我的ShareActionProvider动态地(从听众)查看寻呼机等提交文本

Som*_*ere 6 android android-4.0-ice-cream-sandwich actionbarsherlock shareactionprovider

我正在使用Sherlock Library Action Bar,它类似于ICS动作栏,我被困的地方就是这个

    @Override
public boolean onCreateOptionsMenu(Menu menu) {

    menu.add("Save")
    .setIcon(R.drawable.ic_compose).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    menu.add("Search")
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    SubMenu sub = menu.addSubMenu("Options");
    sub.add(0, SubMenu.NONE, 0, "First");
    sub.add(0,SubMenu.NONE, 1, "Second");
    sub.add(0, SubMenu.NONE, 2, "Three");
    sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    // HERE IS WHere I AM FACING PROBLEM IN
    getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);
    // Set file with share history to the provider and set the share intent.
    actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
    actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME); //this is BRILLIANT WAY TO AVOID REPEATation
    actionProvider.setShareIntent(createShareIntent());

    return super.onCreateOptionsMenu(menu);
}

private Intent createShareIntent() {
    Intent shareIntent = new Intent(Intent.ACTION_SEND);
    shareIntent.setType("text/plain");

    //THIS TEXT IS WHAT I WANT TO OBTAIN DYNAMICALLY
    shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Something goes here");
    return shareIntent;
}
Run Code Online (Sandbox Code Playgroud)

每当我尝试把actionProvider.setShareIntent(createShareIntent());内部放在听众或其他任何地方,actionProvider.setShareIntent(createShareIntent());我得到D/View(11753): onTouchEvent: viewFlags is DISABLED

我希望包含此共享操作提供程序,并希望输入我自己的文本,该文本是在用户输入上生成的.

欢迎提出任何意见.

添加它不起作用

    actionItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Log.e("THIS IS NEVER CALLED", "??");
            return true;
        }
    });
Run Code Online (Sandbox Code Playgroud)

如何获取单击"共享"按钮的更新

小智 -1

我使用这样的菜单:

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.your_share_button_name:
        share();
        return true;

    }
}

    private void share() {
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT,
            "your text");
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
            "your subject");
    startActivity(Intent.createChooser(sharingIntent, "Share using"));
}
Run Code Online (Sandbox Code Playgroud)

就这样。我建议您将菜单的所有布局放在 res/menu 文件夹中的 xml 中。