Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.android.apis;
- import java.util.Timer;
- import java.util.TimerTask;
- //import com.msi.manning.chapter9.xmlanimate.R;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.drawable.AnimationDrawable;
- import android.graphics.drawable.Drawable;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.ImageView;
- import android.widget.TextView;
- public class MyArrayAdapter extends ArrayAdapter<String> {
- private final Activity context;
- private final String[] names;
- private int getViewTimesCalled = 0;
- public MyArrayAdapter(Activity context, String[] names) {
- super(context, R.layout.rowlayout, names);
- // TODO Auto-generated constructor stub
- this.context = context;
- this.names = names;
- }
- public View getView(int position, View convertView, ViewGroup parent){
- LayoutInflater inflater = context.getLayoutInflater();
- View rowView = inflater.inflate(R.layout.rowlayout, null, true);
- Drawable dDraw = null;
- dView holderView = new dView(context, position);
- dDraw = holderView.dDraw;
- /*
- * There is currently an issue where only the first 4
- * imageViews for icon are being set to loop through
- * I suspect it has something to do with my animation
- *
- */
- TextView label = (TextView) rowView.findViewById(R.id.label);
- ImageView gestureImage = (ImageView) rowView.findViewById(R.id.icon);
- gestureImage.setBackgroundResource(R.anim.simple_animation);
- ImageView image = (ImageView) rowView.findViewById(R.id.icon1);
- MyAnimation nAnim = new MyAnimation();
- Timer t = new Timer(false);
- t.schedule(nAnim, 100);
- image.setImageDrawable(dDraw);
- label.setText(names[position]);
- if(names[position].startsWith("Windows7") || names[position].startsWith("iPhone")){
- ImageView imageView = (ImageView) rowView.findViewById(R.id.circle);
- // imageView.setImageResource(android.R.drawable.btn_star_big_on);
- }// the line above causes a nullpoint exception
- return rowView;
- }
- private class dView extends View{
- /* Sets an Integer array that contains the values
- * of all the gesture and symbol images
- * returns the drawable for the int you send in
- */
- Drawable dDraw = null;
- Integer[] symbolImage = new Integer[10];
- Integer[] gestureImage = new Integer[10];
- public dView(Context context, int i) {
- super(context);
- setImageArray();
- // TODO Auto-generated constructor stub
- if(i < 5)
- dDraw = this.getResources().getDrawable(symbolImage[i]);
- else
- dDraw = this.getResources().getDrawable(symbolImage[4]);
- }
- private void setImageArray(){
- symbolImage[0]= R.drawable.circle;
- symbolImage[1]= R.drawable.triangle;
- symbolImage[2]= R.drawable.upsidedowntriangle;
- symbolImage[3]= R.drawable.square;
- symbolImage[4]= R.drawable.star;
- }
- }
- class MyAnimation extends TimerTask{
- public void run(){
- ImageView img = (ImageView)context.findViewById(R.id.icon);
- if(img != null){
- AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
- frameAnimation.start();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement