如何将来自一个Activity的值附加到android中的另一个Activity上

发布于 2024-12-26 07:55:06 字数 5267 浏览 4 评论 0原文

我有两个活动,我从一个活动获取图像像素,并将该值传递给下一个活动,并将其作为字符串存储在文本视图中。并且当我获取下一个像素值并将之前的值传递给第二个活动时文本视图被新的像素值替换。现在我需要的是我想将当前值附加到以前的值。我将向您展示我的代码以获取更多规范

///Selectpassword.java(我在其中获取图像块)

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(我在其中附加像素在文本视图中)

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

  }});
   }



 }

i have two Activity in this i take pixels of image from one activity and pass that value to the next activity and store it in text view As String.AND When i take the next pixel value and pass to the second activity the earlier value in the text View is replaced by the new pixel value.now what i need is that i want to append the current value with previous value .i will show you my code for more specification

///Selectpassword.java(where i get the piels of images)

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 i append the pixels in text view)

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

  }});
   }



 }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯下孤影 2025-01-02 07:55:06

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

我已经将捆绑包从一个页面传递到另一个页面,这意味着。我从画布页面获取像素并将其传递到下一个活动,值从该页面传递到画布页面我在哪里

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

no one answer this question any way i find it myself

I have pass the bundle from one page to another that means.i get the pixel from the canvas page and pass it to the next activity from there the value pass from that page to canvas page where i do

String canvas="";
canvas=canvas+X;(THe X is an integer where i had converted the X in to a String )
and pass the canvas values so that i have successfully append my value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文