DatePickerDialog、AutoCompleteTextView

  DatePickerDialog选择日期,调用showDialog(int id)方法,会执行onCreateDialog方法:

    @Override
    protected Dialog onCreateDialog(int id) {
      switch(id){
        case DATE_PICKER_ID:
          return new DatePickerDialog(this,onDateSetListener,2015,8,12);
      }
      return super.onCreateDialog(id);
    }
    DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {

      @Override
      public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
        Toast.makeText(Forme.this, year + "-" + monthOfYear + "-" + dayOfMonth, Toast.LENGTH_SHORT).show();
      }
    };

  AutoCompleteTextView提供供选择的下拉列表:

    首先在XML文件中声明一个AutoCompleteTextView控件

      <AutoCompleteTextView
        android:id="@+id/autocomplete"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"/>

    然后通过findViewById方法将AutoCompleteTextView对象绑定到该控件上:

      private AutoCompleteTextView autoCompleteTextView = null;
      autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autocomplete);
      List<String> list = new ArrayList<String>();
      list.add("abcd");
      list.add("ddffd");
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_item,list);    //此处list还可以是String数组
      autoCompleteTextView.setAdapter(adapter);

上一篇:ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分


下一篇:Android面试,IntentService的原理及使用