`
kmo
  • 浏览: 17142 次
  • 性别: Icon_minigender_2
  • 来自: 珠海
社区版块
存档分类
最新评论

context menu 与 radio button

 
阅读更多

总算知道menu这个file是做什么用的了

参考了 http://developer.android.com/guide/topics/ui/menus.html#xml

以及这位的博客 http://android.blog.51cto.com/268543/306424 真是多谢了

 

实现的是radio button 和context menu结合 基于listview

SongActivity.java

 

package com.example.hw2;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;



public class SongActivity extends ListActivity{ 
	TextView selection;
	public static final int TWO_ID = Menu.FIRST + 1;
	public static final int SIXTEEN_ID = Menu.FIRST + 2;
	public static final int EIGHT_ID = Menu.FIRST + 3;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.activity_song);
		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, items));
		registerForContextMenu(getListView());
		
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);
        lv.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
            // When clicked, show a toast with the TextView text
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                Toast.LENGTH_SHORT).show();
          }
        });
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,ContextMenu.ContextMenuInfo menuInfo) {
		populateMenu(menu);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.song, menu); 
		populateMenu(menu);
		return (super.onCreateOptionsMenu(menu));
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return (applyMenuChoice(item) || super.onOptionsItemSelected(item));
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		return (applyMenuChoice(item) || super.onContextItemSelected(item));
	}

	private void populateMenu(Menu menu) {
		int groupID = 0;
		
		menu.add(groupID, TWO_ID, Menu.NONE, "2 Pixels");
		menu.add(groupID, EIGHT_ID, Menu.NONE, "8 Pixels");
		menu.add(groupID, SIXTEEN_ID, Menu.NONE, "16 Pixels");
		menu.setGroupCheckable(groupID, true, true); //be the last of group items
	}

	private boolean applyMenuChoice(MenuItem item) {
		switch (item.getItemId()) {
		case EIGHT_ID:
			getListView().setDividerHeight(8);
			return (true);

		case SIXTEEN_ID:
			getListView().setDividerHeight(16);
			return (true);
		case TWO_ID:
			getListView().setDividerHeight(2);
			return (true);
		}

		return (false);
	}
	
	
	static final String[] items = new String[] {
		 "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",
		    "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina",
		    "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan",
		    "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium",
		    "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia",
		    "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory",
		    "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
		    "Cote d'Ivoire", "Cambodia", "Cameroon", "Canada", "Cape Verde",
		    "Cayman Islands", "Central African Republic", "Chad", "Chile", "China",
		    "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo",
		    "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic",
		    "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic",
		    "East Timor", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea",
		    "Estonia", "Ethiopia", "Faeroe Islands", "Falkland Islands", "Fiji", "Finland",
		    "Former Yugoslav Republic of Macedonia", "France", "French Guiana", "French Polynesia",
		    "French Southern Territories", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar",
		    "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau",
		    "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary",
		    "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Jamaica",
		    "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos",
		    "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg",
		    "Macau", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands",
		    "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova",
		    "Monaco", "Mongolia", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia",
		    "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand",
		    "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "Northern Marianas",
		    "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru",
		    "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar",
		    "Reunion", "Romania", "Russia", "Rwanda", "Sqo Tome and Principe", "Saint Helena",
		    "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon",
		    "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal",
		    "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands",
		    "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea",
		    "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Swaziland", "Sweden",
		    "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas",
		    "The Gambia", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey",
		    "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Virgin Islands", "Uganda",
		    "Ukraine", "United Arab Emirates", "United Kingdom",
		    "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan",
		    "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara",
		    "Yemen", "Yugoslavia", "Zambia", "Zimbabwe"
		  };
	
}

 activity_song.xml

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent" 
	android:layout_height="fill_parent" >

	<ListView
		android:id="@android:id/list"
		android:layout_width="fill_parent" 
		android:layout_height="fill_parent"
		android:drawSelectorOnTop="false"
		/>
</LinearLayout>

 menu/song.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    
     <group android:id="@+id/group_1" 
           android:checkableBehavior="single"> 
        <item android:id="@+id/group_item1"
              android:title="@string/pix2"
              />
        <item android:id="@+id/group_item2" 
              android:title="@string/pix8"  
              /> 
        <item android:id="@+id/group_item3" 
              android:title="@string/pix16"  
              />
    </group>  

</menu>

 

效果图:



 选择了16 Pixels后,行间距变为16Pixles:



 

 

 

  • 大小: 116.2 KB
  • 大小: 109.5 KB
分享到:
评论

相关推荐

    Easy Context Menu 1.6(右键菜单管理工具)中文版.zip

    Easy Context Menu 1.6是一款鼠标右键菜单管理器,通常在重装系统后,鼠标右键菜单项目很少,随着系统中软件安装越来越多,有些软件会自动在右键菜单中添加项目,时间长了这些项越来越多,冗长的项目会增加右键...

    Win11 Classic Context Menu,一款经典右键菜单样式恢复工具

    针对这一问题,"Win11 Classic Context Menu"工具应运而生,它旨在帮助用户恢复到经典的Windows 10样式的右键菜单,以提高操作效率和用户体验。 这款工具的主要功能是将Windows 11的现代风格上下文菜单替换为...

    Windows 11 Classic Context Menu v1.1.2023

    为了满足这部分用户的需求,出现了“Windows 11 Classic Context Menu v1.1.2023”这一实用工具,它旨在恢复Windows 11的右键菜单为传统样式。 Windows 11 Classic Context Menu的主要功能是将Windows 11自带的、...

    easy context menu

    "Easy Context Menu"是一款针对Windows系统的实用工具,其主要功能是帮助用户管理和优化电脑的右键菜单。在Windows操作系统中,右键菜单是用户经常使用的功能之一,它提供了快速访问各种命令和操作的途径。然而,...

    Context Menu Tuner Windos 3.0.2 右键菜单功能编辑器

    **Context Menu Tuner Windows 3.0.2:右键菜单功能编辑器详解** 在Windows操作系统中,右键菜单是用户日常操作的重要组成部分,它提供了快速访问常用功能的途径。然而,系统的默认设置可能并不完全符合每个人的...

    android Context Menu With Icon

    在Android开发中,Context Menu是一种常见的用户交互设计,它允许用户在长按或者右键点击一个视图或控件时,弹出一个包含多个选项的菜单。本篇将深入探讨如何在Android应用中实现带有图标的Context Menu,以及相关的...

    Disable Context Menu Items 禁用上下文菜单项 v1.3官方版

    为您提供Disable Context Menu ...基本简介 Disable Context Menu Items是一款多功能的上下文菜单禁止与管理工具,能够为用户提供一个对上下文菜单功能模块管理的平台,同时还可以通过此工具来限制键盘快捷方式,例

    深入理解使用Vue实现Context-Menu的思考与总结

    在了解如何使用Vue实现自定义上下文菜单(Context-Menu)之前,让我们先理解一下上下文菜单的基本概念。上下文菜单是用户对页面元素执行右键操作时弹出的菜单,它允许用户快捷地执行一些与当前元素相关的操作。在Web...

    jQuery Context Menu - jQuery上下文菜单插件

    在使用jQuery Context Menu前,你需要在HTML文件中引入jQuery库和该插件的CSS与JS文件。例如: ```html &lt;!DOCTYPE html&gt; &lt;title&gt;jQuery Context Menu 示例 右键点击我 ...

    Context-Menu.Android源码

    在Android编程中,上下文菜单(Context Menu)是一种特殊的对话框,它只显示与当前屏幕上的特定项目相关的操作。用户通常通过长按某个视图元素来触发上下文菜单的显示。创建和管理上下文菜单涉及到注册菜单项、重写`...

    Windows 11 Classic Context Menu v1.1

    与旧的 windows 相比,Windows 11 中的上下文(右键单击)菜单经过重新设计并保留了有限的条目。它包括一排用于复制、粘贴和删除等基本操作的图标,但在“显示更多选项”按钮后面隐藏了一些您可能想要的功能,这意味...

    jQuery Context Menu多级展开的菜单插件.rar

    jQuery Context Menu是一款强大的JavaScript插件,它允许开发者创建具有多级展开功能的上下文菜单,也就是我们常说的右键菜单。这款插件以其灵活性、易用性和丰富的自定义选项而受到广泛欢迎。在网页设计中,它能为...

    一个通用js右键菜单控件JavaScript Context Menu Control

    "JavaScript Context Menu Control" 是一个专为此目的设计的库,它允许开发者轻松地创建功能强大的右键菜单,且能与任何服务器端或客户端控件无缝集成。 在网页开发中,右键菜单通常用于提供与特定元素相关的特殊...

    基于jQuery 实现的Context Menu 右键菜单插件源码例子

    本文将深入探讨如何基于jQuery实现一个Context Menu(右键菜单)插件,以此来提升网页的交互体验。 首先,让我们理解什么是Context Menu。在网页应用中,当用户在页面上的特定元素上右击时,出现的弹出式菜单就是...

    右键菜单管理 Easy Context Menu 1.6

    右键菜单管理 Easy Context Menu 1.6  Easy Context Menu一个小而有效的应用程序,包括对桌面右键菜单的一系列有益调整,你可以在我的电脑,硬盘,文件和文件夹的右键菜单中添加各种快捷方式。(新浪)  支持简体...

    vue-context-menu-vue js的上下文菜单组件。-Vue.js开发

    在Vue.js的应用中,有时我们需要实现类似右键上下文菜单的功能,这时Vue Context Menu组件就能派上用场。Vue Context Menu是一个专门为Vue.js设计的上下文菜单组件,能够帮助开发者轻松创建具有上下文感知功能的菜单...

    vue-context-menu:HTML元素的简单通用上下文菜单

    安装# install with npmnpm i add-context-menu快速开始# import add-context-menuimport ContextMenu from ' add-context-menu 'import ContextMenuItem from ' add-context-menu 'Vue.use(ContextMenu)Vue.use...

    Context-Menu

    在Android UI设计中,Context Menu是一种重要的交互元素,通常在长按或者特定操作时出现,为用户提供与选定内容相关的操作选项。这个项目可能提供了自定义Context Menu的方法,使得开发者能够创建更加个性化和...

    eclipse下github开源项目Context-Menu.Android

    具体实现及错误解决方法见博客http://my.csdn.net/heiya0409

    bootstrap-js-context-menu.zip

    Bootstrap JS Context Menu是一款基于Bootstrap框架和JavaScript实现的右键菜单插件。这个压缩包`bootstrap-js-context-menu.zip`(注意,文件名中的`.zip`在实际列表中被误写为`.rar`)提供了用于增强网页交互体验...

Global site tag (gtag.js) - Google Analytics