Android中的几种简单小功能实现

自动提醒的设置

根据所输入的内容自动显示出所有相关的提示信息

Step1:在布局文件中定义AutoCompleteTextView

         

 

Step2:在主函数中加载布局,并定义数组,得到控件之后设置适配器ArrayAdapter,并将数据设置给适配器
          

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		String [] names=new String[]{"孙悟空","孙尚香","张无忌","张飞","张牙舞爪","李世民","李小白","不讲理","八戒","aaa","abc","age"};
		AutoCompleteTextView nameText=(AutoCompleteTextView) findViewById(R.id.name);
		ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line,names);
		nameText.setAdapter(adapter);
	}

                注意:也可定义布局中对象为MultiAutoCompleteTextView,可以提示多次

                      setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());//采用逗号作为输入多个对象的分隔符   

AutoCompleteTextView

                           

 MultiAutoCompleteTextView

                             

 Spinner

与自动提醒操作类似,只不过布局中定义的控件为Spinner

 Step1:在布局中定义Spinner

      

 Step2:
         

@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Spinner spinner=(Spinner) findViewById(R.id.spinner);
		
		ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		adapter.add("福尔摩斯");
		adapter.add("阿加莎克里斯蒂");
		adapter.add("柯南道尔");
		spinner.setAdapter(adapter);
	}

效果显示

            

                                                                                                                                                 <!--未完待续-->

 

 

你可能感兴趣的:(Android中的几种简单小功能实现)