0

如果在列表视图上长按,我有以下代码显示菜单:

@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    if (v.getId()==R.id.lvFiles) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
        menu.setHeaderTitle("What would you like to do?");
        String[] menuItems = getResources().getStringArray(R.array.menuSelect); 
        for (int i = 0; i<menuItems.length; i++) {
            menu.add(Menu.NONE, i, i, menuItems[i]);
        }
    }
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    String[] menuItems = getResources().getStringArray(R.array.menuSelect);
    String menuItemName = menuItems[menuItemIndex];

    TextView ck = (TextView) mFrame4.findViewById(R.id.txtTitle);

    Toast.makeText(getActivity(), String.format("Selected %s and %s", menuItemName, ck.getText().toString()), 2000).show();
    return true;
}

我的自定义列表视图调用另一个具有文本视图的布局。如何从列表视图中显示所选列表的文本值?

Toast.makeText(getActivity(), String.format("Selected %s and %s", menuItemName, DISPLAY THE TEXT OF THE SELECTED TEXTVIEW, 2000).show();
4

1 回答 1

4

TextView您可以使用以下代码获取文本:

String txt = ((TextView) info.targetView.findViewById(R.id.txtTitle)).getText().toString();
于 2013-08-09T02:11:50.413 回答