2012-01-13 67 views
0

的另一个活动中附加来自oneActivity的值我有两个活动在这里我从一个活动中获取图像的像素,并将该值传递给下一个活动并将其存储在文本视图中作为String.AND当我采取下一个像素值,并传递到第二个活动文本视图中的较早值被替换为新的像素值。现在我需要的是,我想追加当前值与以前的值.i会告诉你我的代码更规范如何在android

///Selectpassword.java(where我得到的图像的piels)

public class Selectpassword extends Activity { 
/** Called when the activity is first created. */ 
Bitmap overlay;  
Paint pTouch; 
int X = -100; 
int Y = -100; 
Canvas c2; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    Intent mIntent = getIntent(); 
    int intValue = mIntent.getIntExtra("intVariableName", 0); 
    System.out.println("+++++++++++++++++++++"+intValue); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 

    Bitmap mBitmap = BitmapFactory.decodeResource(getResources(),intValue); 
    Bitmap mBitmapover = BitmapFactory.decodeResource(getResources(), intValue); 
    overlay = BitmapFactory.decodeResource(getResources(),intValue).copy(Config.ARGB_8888, true); 
    c2 = new Canvas(overlay); 

    pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);   
    // pTouch.setXfermode(new PorterDuffXfermode(Mode.TARGET); 
    pTouch.setColor(Color.TRANSPARENT); 
    pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL)); 
    setContentView(new BitMapView(this, mBitmap,mBitmapover)); 
} 

class BitMapView extends View { 
    Bitmap mBitmap = null; 
    Bitmap mBitmapover = null; 

    public BitMapView(Context context, Bitmap bm, Bitmap bmover) { 
    super(context); 
    mBitmap = bm; 
    mBitmapover = bmover; 
    } 
    @Override 
    public boolean onTouchEvent(MotionEvent ev) { 

     switch (ev.getAction()) { 

      case MotionEvent.ACTION_DOWN: { 

       X = (int) ev.getX(); 
       Y = (int) ev.getY(); 


       System.out.println("+++++++++++++++++++++++++++++"+X); 
       System.out.println("+++++++++++++++++++++++++++++"+Y); 
       invalidate(); 
       Intent intent = new Intent(Selectpassword.this,Catogry.class); 
       intent.putExtra("intVariableName", X);//i put the value of the pixels 
       // intent.putExtra("intVariableName", Y); 
       startActivity(intent); 

       break; 
      } 

      case MotionEvent.ACTION_MOVE: { 

        X = (int) ev.getX(); 
        Y = (int) ev.getY(); 
        invalidate(); 
        break; 

      }   

      case MotionEvent.ACTION_UP: 

       break; 

     } 
     return true; 
    } 


    @Override 
    protected void onDraw(Canvas canvas) { 
    // called when view is drawn 
    Paint paint = new Paint(); 
    paint.setFilterBitmap(true); 


    //draw background 
    canvas.drawBitmap(mBitmap, 0, 0, null); 
    //copy the default overlay into temporary overlay and punch a hole in it       
    c2.drawBitmap(mBitmapover, 0, 0, null); //exclude this line to show all as you draw 
    c2.drawCircle(X, Y, 80, pTouch); 
    //draw the overlay over the background 
    canvas.drawBitmap(overlay, 0, 0, null); 
    } 
} 

    } 

//Catogry.java(Where我追加的pI在文本视图xels)

public class Catogry extends Activity { 

LinearLayout background; 
Spinner spinnerColor; 
TextView password; 

private static final String[] colorf = 
    { "SELECT ANY FIELD","ANIMAL", 
    "BIRDS", 
    "BABYS", 
    }; 
private ArrayAdapter<String> adapter; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.catogry); 



    spinnerColor = (Spinner)findViewById(R.id.colorspinner); 
    adapter = new ArrayAdapter<String>(this, 
     android.R.layout.simple_spinner_item, colorf); 
    adapter.setDropDownViewResource(
     android.R.layout.simple_spinner_dropdown_item); 
    spinnerColor.setAdapter(adapter); 
    spinnerColor.setSelection(0); 
    Intent mIntent = getIntent(); 
    int passwords = mIntent.getIntExtra("intVariableName", 0);//getting the pixel and convent the values to string 
    password=(TextView)findViewById(R.id.appenpass);//text view 
    // password.setText(Integer.toString(passwords)); 
    password.append(Integer.toString(passwords));//appending the values 
    spinnerColor.setOnItemSelectedListener(
     new Spinner.OnItemSelectedListener(){ 

    public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) { 
    // TODO Auto-generated method stub 
    // setBackgroundColor(spinnerColor.getSelectedItem().toString()); 

    switch(position){ 
    case 0: 

    break; 
    case 1: 
    //call second class 
     Intent animal=new Intent(Catogry.this,Animals.class); 
     startActivity(animal); 

    break; 
    case 2: 
    //call third class 
     Intent bird=new Intent(Catogry.this,Birds.class); 
     startActivity(bird); 
    break; 
    case 3: 
     //call third class 
      Intent baby=new Intent(Catogry.this,Babys.class); 
      startActivity(baby); 
     break; 

    default: 
    break; 
     } 
    } 


    public void onNothingSelected(AdapterView<?> arg0) { 
    // TODO Auto-generated method stub 

    }}); 
    } 



} 

回答

0

没有人以任何方式回答这个问题,我觉得自己

我通过从一个网页到另一个捆绑means.i从画布页,并通过获取像素它从那里到下一个活动从该页面传递的值到canvas页面,在那里我做

String canvas =“”; canvas = canvas + X;(X是一个整数,我已经将X转换为一个字符串) 并传递画布值,以便我成功附加了我的值。