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 list = new ArrayList();
      list.add("abcd");
      list.add("ddffd");
      ArrayAdapter adapter = new ArrayAdapter(this,R.layout.list_item,list);    //此处list还可以是String数组
      autoCompleteTextView.setAdapter(adapter);

声明:DungCry.|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - DatePickerDialog、AutoCompleteTextView


以此热爱,以此谋生。
Le vent se lève, il faut tenter de vivre