Android 3新特性+源码实现(2)


 private Context mContext;
 private int[] mColors;
 
 public ColorAdapter(Context c,int[] colors) {
  mContext = c;
  mColors = colors;
 }
 
 @Override
 public int getCount() {
  return mColors == null ? 0 : mColors.length;
 }


 @Override
 public Object getItem(int position) {
  return mColors == null ? null : mColors[position];
 }


 @Override
 public long getItemId(int position) {
  return position;
 }


 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  LinearLayout.LayoutParams colorLayoutParams = new LinearLayout.LayoutParams(100,100);
  LinearLayout colorLayout = new LinearLayout(mContext);
  colorLayout.setBackgroundColor(mColors[position]);
  colorLayout.setLayoutParams(colorLayoutParams);
  return colorLayout;
 }


}


package com.jsd.demo;


import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterViewFlipper;
import android.widget.Button;
/**
 *
 * @author jankey
 *
 */
public class AdapVIewAnimation extends Activity{


 private int color[] = {Color.CYAN,Color.BLUE,Color.DKGRAY,Color.GREEN,Color.LTGRAY,Color.RED};
 
 private AdapterViewFlipper mAdapterView;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.adapter_anim);
  findViewById();
 }
 
 private void findViewById(){
  mAdapterView = (AdapterViewFlipper) findViewById(R.id.mAdapterViewFlipper);
  ColorAdapter ca = new ColorAdapter(this, color);
  mAdapterView.setAdapter(ca);
  Button piver = (Button) findViewById(R.id.previ);
  piver.setOnClickListener(listener);
  Button next = (Button) findViewById(R.id.next);
  next.setOnClickListener(listener);
 }
 
 private OnClickListener listener = new OnClickListener() {
  @Override
  public void onClick(View v) {
   switch (v.getId()) {
   case R.id.previ:
    mAdapterView.showPrevious();
    break;
   case R.id.next:
    mAdapterView.showNext();
    break;
   }
  }
 };
}

package com.jsd.demo;


import android.app.Activity;
import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.Toast;
import android.widget.CalendarView.OnDateChangeListener;


public class CalendarActivity extends Activity{


 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.calendarview);
  findViewById();
 }
 
 private void findViewById(){
  CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
        calendarView.setOnDateChangeListener(new OnDateChangeListener() {
    @Overridepackage com.jsd.demo;


import android.app.Activity;
import android.os.Bundle;
import android.widget.NumberPicker;
import android.widget.Toast;
import android.widget.NumberPicker.OnValueChangeListener;


public class NumberPickerActivity extends Activity{


 private NumberPicker mNp1 = null,mNp2 = null,mNp3 = null;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.number_picker);
  findViewById();
 }
 
 private void findViewById(){
  mNp1 = (NumberPicker) findViewById(R.id.numberPicker);
  mNp1.setLeft(0);
  mNp1.setMaxValue(24);
  mNp1.setOnValueChangedListener(new OnValueChangeListener() {
   @Override
   public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
    Toast.makeText(NumberPickerActivity.this, picker.getValue()+"hours-", 1).show();
   }
  });
  mNp2 = (NumberPicker) findViewById(R.id.numberPicker2);
  mNp2.setLeft(0);
  mNp2.setMaxValue(60);
  mNp2.setOnValueChangedListener(new OnValueChangeListener() {
   @Override
   public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
    Toast.makeText(NumberPickerActivity.this, picker.getValue()+"minutes", 1).show();
   }
  });
  mNp3 = (NumberPicker) findViewById(R.id.numberPicker3);
  mNp3.setLeft(0);
  mNp3.setMaxValue(60);
  mNp3.setOnValueChangedListener(new OnValueChangeListener() {
   @Override
   public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
    Toast.makeText(NumberPickerActivity.this, picker.getValue()+"seconds", 1).show();
   }
  });
 }
}
    public void onSelectedDayChange(CalendarView view, int year, int month,
      int dayOfMonth) {
     Toast.makeText(CalendarActivity.this, "年:"+year+"-月:"+month+"-日:"+dayOfMonth, 1).show();
     
    }
   });
 }
}

package com.jsd.demo;


import java.io.InputStream;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwgsws.html