`
chenhaodejia
  • 浏览: 115925 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android控件之AutoCompleteTextView、MultiAutoCompleteTextView探究

阅读更多

      在Android中提供了俩种智能输入框,它们是MultiAutoCompleteTextView、AutoCompleteTextView。它们的功能大致一样。下面详细介绍一下。
  一、AutoCompleteTextView
  1.简介
      一个可编辑的文本视图显示自动完成建议当用户键入。建议列表显示在一个下拉菜单,用户可以从中选择一项,以完成输入。建议列表是从一个数据适配器获取的数据。
  2.重要方法
      clearListSelection():清除选中的列表项
      dismissDropDown():如果存在关闭下拉菜单
      getAdapter():获取适配器
  3.实例
  (1)布局文件
    <AutoCompleteTextView android:id="@+id/edit"
                  android:layout_width="match_parent" android:layout_height="wrap_content" />
   (2)程序
    实例化适配器
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, strs);
    设置适配器
      edit.setAdapter(adapter);

二、MultiAutoCompleteTextView
  1.简介
      继承自AutoCompleteTextView,延长AutoCompleteTextView的长度,你必须要提供一个MultiAutoCompleteTextView.Tokenizer来区分不同的子串
  2.重要方法
      enoughToFilter():当文本长度超过阈值时过滤
      performValidation():代替验证整个文本,这个子类方法验证每个单独的文字标记
      setTokenizer(MultiAutoCompleteTextView.Tokenizer t):用户正在输入时,tokenizer设置将用于确定文本相关范围内
  3.实例
  (1)布局文件
    <<MultiAutoCompleteTextView android:id="@+id/edit1"
          android:layout_marginLeft="23px" android:layout_width="match_parent"
          android:layout_height="wrap_content" />   
  (2)程序
    实例化适配器
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, strs);
    设置适配器
      edit.setAdapter(adapter);
    确定范围
    edit1.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());


Android控件之Chronometer(定时器)

 Chronometer是一个简单的定时器,你可以给它一个开始时间,并以此定时,或者如果你不给它一个开始时间,它将会使用你的时间通话开始。默认情况下它会显示在当前定时器的值的形式“分:秒”或“H:MM:SS的”,或者可以使用的Set(字符串)格式的定时器值到一个任意字符串
1.重要属性
android:format:定义时间的格式如:hh:mm:ss
2.重要方法
setBase(long base):设置倒计时定时器
setFormat(String format):设置显示时间的格式。
start():开始计时
stop():停止计时
setOnChronometerTickListener(Chronometer.OnChronometerTickListener listener):当计时器改变时调用。

3.实例
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="4dip"
    android:gravity="center_horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Chronometer android:id="@+id/chronometer"
        android:format="Initial format: "
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:paddingBottom="30dip"
        android:paddingTop="30dip"
        />
    <Button android:id="@+id/start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="开始">
        <requestFocus />
    </Button>
    <Button android:id="@+id/stop"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="停止">
    </Button>
    <Button android:id="@+id/reset"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="重置">
    </Button>
    <Button android:id="@+id/set_format"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="设置格式">
    </Button>
    <Button android:id="@+id/clear_format"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="清除格式">
    </Button>
</LinearLayout>

主程序
package wjq.WidgetDemo;
import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Chronometer;
public class ChronometerDemo extends Activity {
private Chronometer mChronometer;
/* (non-Javadoc)
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
@Override
protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.chronometerpage);
  Button button;
        mChronometer = (Chronometer) findViewById(R.id.chronometer);
        // Watch for button clicks.
        button = (Button) findViewById(R.id.start);
        button.setOnClickListener(mStartListener);
        button = (Button) findViewById(R.id.stop);
        button.setOnClickListener(mStopListener);
        button = (Button) findViewById(R.id.reset);
        button.setOnClickListener(mResetListener);
        button = (Button) findViewById(R.id.set_format);
        button.setOnClickListener(mSetFormatListener);
        button = (Button) findViewById(R.id.clear_format);
        button.setOnClickListener(mClearFormatListener);
    }
    View.OnClickListener mStartListener = new OnClickListener() {
        public void onClick(View v) {
            mChronometer.start();
        }
    };
    View.OnClickListener mStopListener = new OnClickListener() {
        public void onClick(View v) {
            mChronometer.stop();
        }
    };
    View.OnClickListener mResetListener = new OnClickListener() {
        public void onClick(View v) {
            mChronometer.setBase(SystemClock.elapsedRealtime());
        }
    };
    View.OnClickListener mSetFormatListener = new OnClickListener() {
        public void onClick(View v) {
            mChronometer.setFormat("Formatted time (%s)");
        }
    };
    View.OnClickListener mClearFormatListener = new OnClickListener() {
        public void onClick(View v) {
            mChronometer.setFormat(null);
        }
    };
}


Android 控件之DatePicker,TimePicker,Calender
 在Android中关于日期时间的类有TimePicker、DatePicker、TimePickerDialog、DatePickerDialog、Calendar。其中TimePickerDialog、DatePickerDialog是对话框形式。
一、TimePicker
  查看一个在24小时或上午/下午模式下一天的时间。
  1.重要方法
    setCurrentMinute(Integer currentMinute)设置当前时间的分钟
    getCurrentMinute()获取当前时间的分钟
    setEnabled(boolean enabled)设置当前视图是否可以编辑。
    setOnTimeChangedListener(TimePicker.OnTimeChangedListener onTimeChangedListener)当时间改变时调用
  2.实例:
timePicker=(TimePicker)findViewById(R.id.timePicker);
  timePicker.setCurrentHour(16);
  timePicker.setCurrentMinute(10);
  updateDisplay(16,10);
  timePicker.setOnTimeChangedListener(this);

二、DatePicker
    1.重要方法
      getDayOfMonth():获取当前Day
      getMonth():获取当前月
      getYear()获取当前年
      updateDate(int year, int monthOfYear, int dayOfMonth):更新日期
三、TimePickerDialog、DatePickerDialog
  以对话框形式显示日期时间视图
四、Calendar
    日历是设定年度日期对象和一个整数字段之间转换的抽象基类,如,月,日,小时等。
  实例
final Calendar calendar=Calendar.getInstance();
  mYear=calendar.get(Calendar.YEAR);
  mMonth=calendar.get(Calendar.MONTH);
  mDay=calendar.get(Calendar.DAY_OF_MONTH);
  mHour=calendar.get(Calendar.HOUR_OF_DAY);
  mMinute=calendar.get(Calendar.MINUTE);
此类方法不做赘述



Android 控件之Gallery图片集

一、简介
  在中心锁定,水平显示列表的项。
二、实例
1.布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
   android:orientation="vertical"
  android:layout_height="wrap_content">


  <Gallery xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Gallery android:id="@+id/gallery1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:spacing="16dp"
    />
</LinearLayout>

</LinearLayout>

2.属性文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="TogglePrefAttrs">
        <attr name="android:preferenceLayoutChild" />
    </declare-styleable>


    <!-- These are the attributes that we want to retrieve from the theme
         in view/Gallery1.java -->
    <declare-styleable name="Gallery1">
        <attr name="android:galleryItemBackground" />
    </declare-styleable>


     <declare-styleable name="LabelView">
        <attr name="text" format="string" />
        <attr name="textColor" format="color" />
        <attr name="textSize" format="dimension" />
    </declare-styleable>
</resources>

3.代码
/**
*
*/
package wjq.WidgetDemo;
import android.R.layout;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.SimpleCursorAdapter;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
/**
* @author 记忆的永恒
*
*/
public class GalleryDemo extends Activity {
private Gallery gallery;
private Gallery gallery1;
/*
  * (non-Javadoc)
  *
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
@Override
protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.gallerypage);
  gallery = (Gallery) findViewById(R.id.gallery);
  gallery.setAdapter(new ImageAdapter(this));


  registerForContextMenu(gallery);


   Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
         startManagingCursor(c);


         SpinnerAdapter adapter = new SimpleCursorAdapter(this,
         // Use a template that displays a text view
                 android.R.layout.simple_gallery_item,
                 // Give the cursor to the list adatper
                 c,
                 // Map the NAME column in the people database to...
                 new String[] {People.NAME},
                 // The "text1" view defined in the XML template
                 new int[] { android.R.id.text1 });
         gallery1= (Gallery) findViewById(R.id.gallery1);
         gallery1.setAdapter(adapter);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
   ContextMenuInfo menuInfo) {
  menu.add("Action");
}
@Override
public boolean onContextItemSelected(MenuItem item) {
  AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
    .getMenuInfo();
  Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT)
    .show();
  return true;
}


public class ImageAdapter extends BaseAdapter {
  int mGalleryItemBackground;
  private Context mContext;
  private Integer[] mImageIds = { R.drawable.b, R.drawable.c,
    R.drawable.d, R.drawable.f, R.drawable.g };
  public ImageAdapter(Context context) {
   mContext = context;
   TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
   mGalleryItemBackground = a.getResourceId(
     R.styleable.Gallery1_android_galleryItemBackground, 0);
   a.recycle();
  }
  @Override
  public int getCount() {
   return mImageIds.length;
  }
  @Override
  public Object getItem(int position) {
   return position;
  }
  @Override
  public long getItemId(int position) {
   return position;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
   ImageView i = new ImageView(mContext);
   i.setImageResource(mImageIds[position]);
   i.setScaleType(ImageView.ScaleType.FIT_XY);
   i.setLayoutParams(new Gallery.LayoutParams(300, 400));
   // The preferred Gallery item background
   i.setBackgroundResource(mGalleryItemBackground);
   return i;
  }
}

}




Android 控件之ImageSwitcher图片切换器

一、重要方法
    setImageURI(Uri uri):设置图片地址
    setImageResource(int resid):设置图片资源库
    setImageDrawable(Drawable drawable):绘制图片
二、实例
   <ImageSwitcher android:id="@+id/switcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
    />
   
    <Gallery android:id="@+id/gallery"
        android:background="#55000000"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
       
        android:gravity="center_vertical"
        android:spacing="16dp"
    />

is = (ImageSwitcher) findViewById(R.id.switcher);
is.setFactory(this);

设置动画效果
  is.setInAnimation(AnimationUtils.loadAnimation(this,
    android.R.anim.fade_in));
  is.setOutAnimation(AnimationUtils.loadAnimation(this,
    android.R.anim.fade_out));
  
三、完整代码
1.布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageSwitcher android:id="@+id/switcher"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
    />


    <Gallery android:id="@+id/gallery"
        android:background="#55000000"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"


        android:gravity="center_vertical"
        android:spacing="16dp"
    />
</RelativeLayout>
   2.Java代码
package wjq.WidgetDemo;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Gallery.LayoutParams;
import android.widget.ViewSwitcher.ViewFactory;
public class ImageSwitcherDemo extends Activity implements
  OnItemSelectedListener, ViewFactory {
private ImageSwitcher is;
private Gallery gallery;
private Integer[] mThumbIds = { R.drawable.b, R.drawable.c,
   R.drawable.d, R.drawable.f, R.drawable.g,
   };
private Integer[] mImageIds = { R.drawable.b, R.drawable.c,
   R.drawable.d, R.drawable.f, R.drawable.g, };
/*
  * (non-Javadoc)
  *
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
@Override
protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  requestWindowFeature(Window.FEATURE_NO_TITLE);
  setContentView(R.layout.imageswitcherpage);
  is = (ImageSwitcher) findViewById(R.id.switcher);
  is.setFactory(this);
  is.setInAnimation(AnimationUtils.loadAnimation(this,
    android.R.anim.fade_in));
  is.setOutAnimation(AnimationUtils.loadAnimation(this,
    android.R.anim.fade_out));
  gallery = (Gallery) findViewById(R.id.gallery);
  gallery.setAdapter(new ImageAdapter(this));
  gallery.setOnItemSelectedListener(this);
}
@Override
public View makeView() {
  ImageView i = new ImageView(this);
  i.setBackgroundColor(0xFF000000);
  i.setScaleType(ImageView.ScaleType.FIT_CENTER);
  i.setLayoutParams(new ImageSwitcher.LayoutParams(
    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  return i;
}
public class ImageAdapter extends BaseAdapter {
  public ImageAdapter(Context c) {
   mContext = c;
  }
  public int getCount() {
   return mThumbIds.length;
  }
  public Object getItem(int position) {
   return position;
  }
  public long getItemId(int position) {
   return position;
  }
  public View getView(int position, View convertView, ViewGroup parent) {
   ImageView i = new ImageView(mContext);
   i.setImageResource(mThumbIds[position]);
   i.setAdjustViewBounds(true);
   i.setLayoutParams(new Gallery.LayoutParams(
     LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
   i.setBackgroundResource(R.drawable.e);
   return i;
  }
  private Context mContext;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
   long id) {
  is.setImageResource(mImageIds[position]);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
  // TODO Auto-generated method stub
}
}



Android 控件之ProgressBar进度条

下面详细介绍ProgressBar
一、说明
  在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度。一个进度条也可不确定其进度。在不确定模式下,进度条显示循环动画。这种模式常用于应用程序使用任务的长度是未知的。
二、XML重要属性
    android:progressBarStyle:默认进度条样式
    android:progressBarStyleHorizontal:水平样式


三、重要方法
    getMax():返回这个进度条的范围的上限
    getProgress():返回进度
    getSecondaryProgress():返回次要进度
    incrementProgressBy(int diff):指定增加的进度
    isIndeterminate():指示进度条是否在不确定模式下
    setIndeterminate(boolean indeterminate):设置不确定模式下
    setVisibility(int v):设置该进度条是否可视
四、重要事件
    onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件
五、实例
1.布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ProgressBar android:id="@+id/progress_horizontal"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="200dip"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50"
        android:secondaryProgress="75" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="默认进度条" />       
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button android:id="@+id/decrease"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="减少" />
        <Button android:id="@+id/increase"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="增加" />
    </LinearLayout>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="自定义进度条" />       
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button android:id="@+id/decrease_secondary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="第二减少" />
        <Button android:id="@+id/increase_secondary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="第二增加" />
    </LinearLayout>
</LinearLayout>

2.Java代码
package wjq.WidgetDemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
public class ProgressBarDemo extends Activity {
/* (non-Javadoc)
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
@Override
protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);


   requestWindowFeature(Window.FEATURE_PROGRESS);
         setContentView(R.layout.probarpage);
         setProgressBarVisibility(true);


         final ProgressBar progressHorizontal = (ProgressBar) findViewById(R.id.progress_horizontal);
         setProgress(progressHorizontal.getProgress() * 100);
         setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100);


         Button button = (Button) findViewById(R.id.increase);
         button.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 progressHorizontal.incrementProgressBy(1);
                 // Title progress is in range 0..10000
                 setProgress(100 * progressHorizontal.getProgress());
             }
         });
         button = (Button) findViewById(R.id.decrease);
         button.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 progressHorizontal.incrementProgressBy(-1);
                 // Title progress is in range 0..10000
                 setProgress(100 * progressHorizontal.getProgress());
             }
         });
         button = (Button) findViewById(R.id.increase_secondary);
         button.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 progressHorizontal.incrementSecondaryProgressBy(1);
                 // Title progress is in range 0..10000
                 setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
             }
         });
         button = (Button) findViewById(R.id.decrease_secondary);
         button.setOnClickListener(new Button.OnClickListener() {
             public void onClick(View v) {
                 progressHorizontal.incrementSecondaryProgressBy(-1);
                 // Title progress is in range 0..10000
                 setSecondaryProgress(100 * progressHorizontal.getSecondaryProgress());
             }
         });


}
}


Android 控件之RatingBar评分条

一、概述
    RatingBar是SeekBar和ProgressBar的扩展,用星星来评级。使用的默认大小RatingBar时,用户可以触摸/拖动或使用键来设置评分,它有俩种样式(大、小),其中大的只适合指示,不适合于用户交互。
二、实例
1.布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:paddingLeft="10dip"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RatingBar android:id="@+id/ratingbar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="3"
        android:rating="2.5" />
    <RatingBar android:id="@+id/ratingbar2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:rating="2.25" />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip">


        <TextView android:id="@+id/rating"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


        <RatingBar android:id="@+id/small_ratingbar"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_marginLeft="5dip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical" />


    </LinearLayout>
    <RatingBar android:id="@+id/indicator_ratingbar"
        style="?android:attr/ratingBarStyleIndicator"
        android:layout_marginLeft="5dip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical" />


</LinearLayout>
2.Java代码
package wjq.WidgetDemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.RatingBar.OnRatingBarChangeListener;
public class RatingBarDemo extends Activity implements
  OnRatingBarChangeListener {
private RatingBar mSmallRatingBar;
private RatingBar mIndicatorRatingBar;
private TextView mRatingText;
/*
  * (non-Javadoc)
  *
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
@Override
protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.ratingbarpage);


   mRatingText = (TextView) findViewById(R.id.rating);
         // We copy the most recently changed rating on to these indicator-only
         // rating bars
         mIndicatorRatingBar = (RatingBar) findViewById(R.id.indicator_ratingbar);
         mSmallRatingBar = (RatingBar) findViewById(R.id.small_ratingbar);


         // The different rating bars in the layout. Assign the listener to us.
         ((RatingBar)findViewById(R.id.ratingbar1)).setOnRatingBarChangeListener(this);
         ((RatingBar)findViewById(R.id.ratingbar2)).setOnRatingBarChangeListener(this);
}
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
   boolean fromUser) {
   final int numStars = ratingBar.getNumStars();
         mRatingText.setText(
                  " 受欢迎度" + rating + "/" + numStars);
         // Since this rating bar is updated to reflect any of the other rating
         // bars, we should update it to the current values.
         if (mIndicatorRatingBar.getNumStars() != numStars) {
             mIndicatorRatingBar.setNumStars(numStars);
             mSmallRatingBar.setNumStars(numStars);
         }
         if (mIndicatorRatingBar.getRating() != rating) {
             mIndicatorRatingBar.setRating(rating);
             mSmallRatingBar.setRating(rating);
         }
         final float ratingBarStepSize = ratingBar.getStepSize();
         if (mIndicatorRatingBar.getStepSize() != ratingBarStepSize) {
             mIndicatorRatingBar.setStepSize(ratingBarStepSize);
             mSmallRatingBar.setStepSize(ratingBarStepSize);
         }
}
}


Android 控件之Spinner

一、概述
    Spinner是一个每次只能选择所有项的一个项的控件。它的项来自于与之相关联的适配器中。
二、重要属性
    android:prompt:当Spinner对话框关闭时显示该提示
三、重要方法
    setPrompt(CharSequence prompt):设置当Spinner对话框关闭时显示的提示
    performClick():如果它被定义就调用此视图的OnClickListener
    setOnItemClickListener(AdapterView.OnItemClickListener l):当项被点击时调用
    onDetachedFromWindow():当Spinner脱离窗口时被调用。
四、完整代码
public class SpinnerDemo extends Activity {
   @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.spinnerpage);
         Spinner s1 = (Spinner) findViewById(R.id.spinnercolor);
         ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                 this, R.array.colors, android.R.layout.simple_spinner_item);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         s1.setAdapter(adapter);
         s1.setOnItemSelectedListener(
                 new OnItemSelectedListener() {
                     public void onItemSelected(
                             AdapterView<?> parent, View view, int position, long id) {
                         showToast("Spinner1: position=" + position + " id=" + id);
                     }
                     public void onNothingSelected(AdapterView<?> parent) {
                         showToast("Spinner1: unselected");
                     }
                 });
         Spinner s2 = (Spinner) findViewById(R.id.spinnerplanet);
         adapter = ArrayAdapter.createFromResource(this, R.array.planets,
                 android.R.layout.simple_spinner_item);
         adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
         s2.setAdapter(adapter);
         s2.setOnItemSelectedListener(
                 new OnItemSelectedListener() {
                     public void onItemSelected(
                             AdapterView<?> parent, View view, int position, long id) {
                         showToast("Spinner2: position=" + position+1 + " id=" + id+1);
                     }
                     public void onNothingSelected(AdapterView<?> parent) {
                         showToast("Spinner2: unselected");
                     }
                 });
     }


private void showToast(CharSequence msg) {
         Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
     }
}





分享到:
评论

相关推荐

    东营市乡镇边界,矢量边界,shp格式

    矢量边界,行政区域边界,精确到乡镇街道,可直接导入arcgis使用

    Java SSM 商户管理系统 客户管理 库存管理 销售报表 项目源码 本商品卖的是源码,合适的地方.zip

    毕业设计

    075.JSP+SQL宿舍管理系统.zip

    毕业设计

    经验贝叶斯EB的简单例子

    经验贝叶斯EB的简单例子

    69页-智慧园区综合管理平台解决方案.pdf

    智慧园区,作为现代城市发展的新形态,旨在通过高度集成的信息化系统,实现园区的智能化管理与服务。该方案提出,利用智能手环、定制APP、园区管理系统及物联网技术,将园区的各类设施与设备紧密相连,形成一个高效、便捷、安全的智能网络。从智慧社区到智慧酒店,从智慧景区到智慧康养,再到智慧生态,五大应用板块覆盖了园区的每一个角落,为居民、游客及工作人员提供了全方位、个性化的服务体验。例如,智能手环不仅能实现定位、支付、求助等功能,还能监测用户健康状况,让科技真正服务于生活。而智慧景区的建设,更是通过大数据分析、智能票务、电子围栏等先进技术,提升了游客的游玩体验,确保了景区的安全有序。 尤为值得一提的是,方案中的智慧康养服务,展现了科技对人文关怀的深刻体现。通过智慧手环与传感器,自动感知老人身体状态,及时通知家属或医疗机构,有效解决了“空巢老人”的照护难题。同时,智慧生态管理系统的应用,实现了对大气、水、植被等环境要素的实时监测与智能调控,为园区的绿色发展提供了有力保障。此外,方案还提出了建立全域旅游营销平台,整合区域旅游资源,推动旅游业与其他产业的深度融合,为区域经济的转型升级注入了新的活力。 总而言之,这份智慧园区建设方案以其前瞻性的理念、创新性的技术和人性化的服务设计,为我们展示了一个充满智慧与活力的未来园区图景。它不仅提升了园区的运营效率和服务质量,更让科技真正融入了人们的生活,带来了前所未有的便捷与舒适。对于正在规划或实施智慧园区建设的决策者而言,这份方案无疑提供了一份宝贵的参考与启示,激发了他们对于未来智慧生活的无限遐想与憧憬。

    数学建模相关主题资源2

    数学建模相关主题资源2

    SQL编程语言在数据科学领域的面试技巧及核心功能解析

    内容概要:本文围绕SQL在求职和实际工作中的应用展开,详细解析了SQL的重要性及其在不同行业中不可替代的地位。文章首先强调了SQL作为“一切数据工作的起点”,是数据分析、数据挖掘等领域必不可少的技能,并介绍了SQL与其他编程语言在就业市场的对比情况。随后重点探讨了SQL在面试过程中可能出现的挑战与应对策略,具体涉及到询问澄清问题、正确选择JOIN语句类型、恰当使用GROUP BY及相关过滤条件的区别、理解和运用窗口函数等方面,并给出了详细的实例和技巧提示。另外提醒面试者要注意重复值和空值等问题,倡导与面试官及时沟通。文中引用IEEE Spectrum编程语言排行榜证明了SQL不仅广泛应用于各行各业,在就业市场上也最受欢迎。 适用人群:从事或打算转入数据科学领域(包括但不限于数据分析师、数据科学家、数据工程师等职业方向),并对掌握和深入理解SQL有一定需求的专业人士,尤其是正准备涉及SQL相关技术面试的求职者。 使用场景及目标:帮助用户明确在面对复杂的SQL查询题目时能够更加灵活应对,提高解题效率的同时确保准确性;同时让用户意识到SQL不仅仅是简单的数据库查询工具,而是贯穿整个数据处理流程的基础能力之一,进而激发他们进一步探索的热情。 其他说明:SQL在性能方面优于Excel尤其适用于大规模数据操作;各知名企业仍将其视为标准数据操作手段。此外还提供了对初学者友好的建议,针对留学生普遍面临的难题如零散的学习资料、昂贵且效果不佳的付费教程以及难以跟上的纯英教学视频给出了改进的方向。

    COMSOL仿真揭示石墨烯临界耦合光吸收特性:费米能级调控下的光学性能探究,COMSOL仿真揭示石墨烯临界耦合光吸收特性:费米能级调控下的光学性能探究,COMSOL 准 BIC控制石墨烯临界耦合光吸收

    COMSOL仿真揭示石墨烯临界耦合光吸收特性:费米能级调控下的光学性能探究,COMSOL仿真揭示石墨烯临界耦合光吸收特性:费米能级调控下的光学性能探究,COMSOL 准 BIC控制石墨烯临界耦合光吸收。 COMSOL 光学仿真,石墨烯,光吸收,费米能级可调下图是仿真文件截图,所见即所得。 ,COMSOL; 准BIC; 石墨烯; 临界耦合光吸收; 光学仿真; 费米能级可调。,COMSOL仿真:石墨烯光吸收的BIC控制与费米能级调节

    Labview与Proteus串口仿真下的温度采集与报警系统:Keil单片机程序及全套视频源码解析,Labview与Proteus串口仿真温度采集及上位机报警系统实战教程:设定阈值的Keil程序源码分

    Labview与Proteus串口仿真下的温度采集与报警系统:Keil单片机程序及全套视频源码解析,Labview与Proteus串口仿真温度采集及上位机报警系统实战教程:设定阈值的Keil程序源码分享,labview 和proteus 联合串口仿真 温度采集 上位机报警 设定阈值单片机keil程序 整套视频仿真源码 ,关键词:LabVIEW;Proteus;串口仿真;温度采集;上位机报警;阈值设定;Keil程序;视频仿真源码。,LabVIEW与Proteus联合串口仿真:温度采集与报警系统,Keil程序与阈值设定全套视频源码

    整车性能目标书:涵盖燃油车、混动车及纯电动车型的十六个性能模块目标定义模板与集成开发指南,整车性能目标书:涵盖燃油车、混动车及纯电动车型的十六个性能模块目标定义模板与集成开发指南,整车性能目标书,汽车

    整车性能目标书:涵盖燃油车、混动车及纯电动车型的十六个性能模块目标定义模板与集成开发指南,整车性能目标书:涵盖燃油车、混动车及纯电动车型的十六个性能模块目标定义模板与集成开发指南,整车性能目标书,汽车性能目标书,十六个性能模块目标定义模板,包含燃油车、混动车型及纯电动车型。 对于整车性能的集成开发具有较高的参考价值 ,整车性能目标书;汽车性能目标书;性能模块目标定义模板;燃油车;混动车型;纯电动车型;集成开发;参考价值,《汽车性能模块化目标书:燃油车、混动车及纯电动车的集成开发参考》

    面板数据熵值法Stata代码( 附样本数据和结果).rar

    熵值法stata代码(含stata代码+样本数据) 面板熵值法是一种在多指标综合评价中常用的数学方法,主要用于对不同的评价对象进行量化分析,以确定各个指标在综合评价中的权重。该方法结合了熵值理论和面板数据分析,能够有效地处理包含多个指标的复杂数据。

    “电子电路”仿真资源(Multisim、Proteus、PCB等)

    “电子电路”仿真资源(Multisim、Proteus、PCB等)

    107_xee_water_consumption.txt

    在 GEE(Google Earth Engine)中,XEE 包是一个用于处理和分析地理空间数据的工具。以下是对 GEE 中 XEE 包的具体介绍: 主要特性 地理数据处理:提供强大的函数和工具,用于处理遥感影像和其他地理空间数据。 高效计算:利用云计算能力,支持大规模数据集的快速处理。 可视化:内置可视化工具,方便用户查看和分析数据。 集成性:可以与其他 GEE API 和工具无缝集成,支持多种数据源。 适用场景 环境监测:用于监测森林砍伐、城市扩展、水体变化等环境问题。 农业分析:分析作物生长、土地利用变化等农业相关数据。 气候研究:研究气候变化对生态系统和人类活动的影响。

    C++指针与内存管理详解:避免常见错误及最佳实践

    内容概要:本文介绍了C++编程中常见指针错误及其解决方案,并涵盖了模板元编程的基础知识和发展趋势,强调了高效流操作的最新进展——std::spanstream。文章通过一系列典型错误解释了指针的安全使用原则,强调指针初始化、内存管理和引用安全的重要性。随后介绍了模板元编程的核心特性,展示了编译期计算、类型萃取等高级编程技巧的应用场景。最后,阐述了C++23中引入的新特性std::spanstream的优势,对比传统流处理方法展现了更高的效率和灵活性。此外,还给出了针对求职者的C++技术栈学习建议,涵盖了语言基础、数据结构与算法及计算机科学基础领域内的多项学习资源与实战练习。 适合人群:正在学习C++编程的学生、从事C++开发的技术人员以及其他想要深入了解C++语言高级特性的开发者。 使用场景及目标:帮助读者掌握C++中的指针规则,预防潜在陷阱;介绍模板元编程的相关技术和优化方法;使读者理解新引入的标准库组件,提高程序性能;引导C++学习者按照有效的路径规划自己的技术栈发展路线。 阅读建议:对于指针部分的内容,应当结合实际代码样例反复实践,以便加深理解和记忆;在研究模板元编程时,要从简单的例子出发逐步建立复杂模型的理解能力,培养解决抽象问题的能力;而对于C++23带来的变化,则可以通过阅读官方文档并尝试最新标准特性来加深印象;针对求职准备,应结合个人兴趣和技术发展方向制定合理的学习计划,并注重积累高质量的实际项目经验。

    Java读写FM1208CPU卡源码

    JNA、JNI, Java两种不同调用DLL、SO动态库方式读写FM1208 CPU卡示例源码,包括初始化CPU卡、创建文件、修改文件密钥、读写文件数据等操作。支持Windows系统、支持龙芯Mips、LoongArch、海思麒麟鲲鹏飞腾Arm、海光兆芯x86_Amd64等架构平台的国产统信、麒麟等Linux系统编译运行,内有jna-4.5.0.jar包,vx13822155058 qq954486673

    Linux系统入门到精通:从基础命令到服务管理和日志解析

    内容概要:本文全面介绍了Linux系统的各个方面,涵盖入门知识、基础操作、进阶技巧以及高级管理技术。首先概述了Linux的特点及其广泛的应用领域,并讲解了Linux环境的搭建方法(如使用虚拟机安装CentOS),随后深入剖析了一系列常用命令和快捷键,涉及文件系统管理、用户和权限设置、进程和磁盘管理等内容。此外,还讨论了服务管理的相关指令(如nohup、systemctl)以及日志记录和轮替的最佳实践。这不仅为初学者提供了一个完整的知识框架,也为中级和高级用户提供深入理解和优化系统的方法。 适合人群:适用于有意深入了解Linux系统的学生和专业技术人员,特别是需要掌握服务器运维技能的人群。 使用场景及目标:本文适合初次接触Linux的操作员了解基本概念;也适合作为培训教材,指导学生逐步掌握各项技能。对于有一定经验的技术人员而言,则可以帮助他们巩固基础知识,并探索更多的系统维护和优化可能性。 阅读建议:建议按照文章结构循序渐进地学习相关内容,尤其是结合实际练习操作来加深记忆和理解。遇到复杂的问题时可以通过查阅官方文档或在线资源获得更多帮助。

    企业绩效考核制度详解:运维部门绩效管理流程规范及其应用

    内容概要:本文档详细介绍了企业在规范运维部门绩效管理过程中所建立的一套绩效考核制度。首先阐述了绩效考核制度设立的目的为确保绩效目标得以衡量与追踪,并确保员工与公司共同成长与发展。其次规定范围覆盖公司所有在职员工,并详细列明了从总经理到一线员工在内的不同角色的职责范围。再则描述了完整的绩效工作流程,即从年初开始制定绩效管理活动计划,经过与每个员工制定具体的绩效目标,在绩效考核周期之内对员工的工作进展和问题解决状况进行持续的监督跟进,并且在每周期结束前完成员工绩效的评估和反馈工作,同时利用绩效评估结果对员工作出保留或异动的相关决定,最后进行绩效管理活动总结以为来年提供参考。此外还强调了整个过程中必要的相关文档保存,如员工绩效评估表。 适合人群:企业管理层,HR专业人士及对现代企业内部运营管理感兴趣的读者。 使用场景及目标:①管理层需要理解如何规范和有效实施企业内部绩效管理,以提高公司运营效率和员工满意度;②HR人士可以通过参考此文档来优化自己公司的绩效管理体系;③对企业和组织管理有兴趣的研究员亦可借鉴。 阅读建议:读者应重点关注各个层级管理者和员工在整个流程中的角色和责任,以期更好地理解

    基于MATLAB Simulink的LCL三相并网逆变器仿真模型:采用交流电流内环PR控制与SVPWM-PWM波控制研究,基于MATLAB Simulink的LCL三相并网逆变器仿真模型研究:采用比例

    基于MATLAB Simulink的LCL三相并网逆变器仿真模型:采用交流电流内环PR控制与SVPWM-PWM波控制研究,基于MATLAB Simulink的LCL三相并网逆变器仿真模型研究:采用比例谐振控制与交流SVPWM控制策略及参考文献解析,LCL_Three_Phase_inverter:基于MATLAB Simulink的LCL三相并网逆变器仿真模型,交流电流内环才用PR(比例谐振)控制,PWM波采用SVPWM控制,附带对应的参考文献。 仿真条件:MATLAB Simulink R2015b,前如需转成低版本格式请提前告知,谢谢。 ,LCL三相并网逆变器; LCL_Three_Phase_inverter; MATLAB Simulink; PR控制; SVPWM控制; 仿真模型; 参考文献; 仿真条件; R2015b版本,基于PR控制与SVPWM的LCL三相并网逆变器Simulink仿真模型研究

    内点法求解标准节点系统最优潮流计算的稳定程序,注释清晰,通用性强,内点法用于标准节点系统的最优潮流计算:稳定、通用且注释清晰的matlab程序,内点法最优潮流程序matlab 采用内点法对14标准节点

    内点法求解标准节点系统最优潮流计算的稳定程序,注释清晰,通用性强,内点法用于标准节点系统的最优潮流计算:稳定、通用且注释清晰的matlab程序,内点法最优潮流程序matlab 采用内点法对14标准节点系统进行最优潮流计算,程序运行稳定,注释清楚,通用性强 ,内点法; 最优潮流程序; MATLAB; 14标准节点系统; 稳定运行; 清晰注释; 通用性强。,Matlab内点法最优潮流程序:稳定高效,通用性强,适用于14节点系统

    17suiea3.apk?v=1741006890849

    17suiea3.apk?v=1741006890849

Global site tag (gtag.js) - Google Analytics