使用上下文操作栏获取每个所选项的值

时间:2017-06-03 05:52:02

标签: java android contextual-action-bar

我正在使用上下文操作栏,并希望在点击“邮件”后检索所选的每个值以传递给其他活动。按钮。我怎么能这样做?e

CAB代码。

<xsl:template match="Element">
    <xsl:copy>
        <xsl:for-each-group select="P" group-starting-with="Level1/Level2">
                <P>
                    <xsl:sequence select="current-group()"/>
                </P>
        </xsl:for-each-group>
    </xsl:copy>
</xsl:template>

选择适配器类,用于定义对象mAdapter = new SelectionAdapter(this, R.layout.activity_result, R.id.name, new String[] {TAG_NAME, TAG_ROOM_PRICE}); setListAdapter(mAdapter); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() { private int nr = 0; @Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { nr = 0; MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.email: } return false; } @Override public void onDestroyActionMode(android.view.ActionMode mode) { mAdapter.clearSelection(); } @Override public void onItemCheckedStateChanged(android.view.ActionMode mode, int position, long id, boolean checked) { if (checked) { nr++; mAdapter.setNewSelection(position, checked); } else { nr--; mAdapter.removeSelection(position); } mode.setTitle("No: of resorts selected: " + nr); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { //String name = ((TextView) view.findViewById(R.id.name)).getText().toString(); getListView().setItemChecked(position, !mAdapter.isPositionChecked(position)); return true; } });

mAdapter

我希望检索我所做的每个选择的字符串值

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

mAdapter.setNewSelection(position, checked);
                String get_list = resortsList.get(position).get(TAG_NAME);
                stringList.add(get_list);

删除取消选择时选择的项目:`int i;

for(i = 0 ; i < stringList.size(); i++){
     if(stringList.get(i).equals(resortsList.get(position).get(TAG_NAME))){
          stringList.remove(i);
          Log.d("String List: ", stringList.toString());
          break;
          }
 }`