我如何可以通过在Android的活动之间的图像视图 [英] How can i pass image view between activities in android

查看:102
本文介绍了我如何可以通过在Android的活动之间的图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要ImageView的形式一个活动发送到另一个活动。当我试图用包的概念,然后B级在它显示空指针exception.Below是我的$ C $ A类C至妙传A级图像视图B级。

I want to send the ImageView form one activity to another activity. When i am trying to pass the image view from Class A to Class B using bundle concept then in class B it's showing null pointer exception.Below is my code of class A.

  public class First extends Activity {
    Cursor cursor1;
    boolean y,n;
    ImageView login;
    Button  enroll;
    String AndroidId;
    SQLiteDatabase db1,db;
    private ContentValues values;
    DopenHelper helper;


    String TableName = "tbl_finger";
    ImageView FingerImageData;
    String fingerID,DivID,enrolledtype;



    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();        
        helper.close();
        db.close();
        db1.close();

    }

    protected void onResume() 
    {
        // TODO Auto-generated method stub
        super.onResume();
        helper =new DopenHelper(getApplicationContext());
        db=helper.getWritableDatabase();
        db1=helper.getWritableDatabase();
        values=new ContentValues();
        enroll=(Button)findViewById(R.id.enroll_button);



        FingerImageData = (ImageView)findViewById(R.id.fingerid);
         AndroidId = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
         //"[B@40520c28";
         //"com.a1technology.remoteid.First@4050f508";      

            helper = new DopenHelper(First.this);           

            cursor1 = db1.rawQuery("SELECT  template,enrolled,deviceID FROM " + TableName,  null);

            try {

                db1 = this.openOrCreateDatabase("remoteid.db", MODE_PRIVATE, null);

                if(cursor1 != null )
                {
                    if(cursor1.moveToFirst())
                    {
                        do {
                            DivID = cursor1.getString(cursor1.getColumnIndex("deviceID"));
                            fingerID = cursor1.getString(cursor1.getColumnIndex("template"));
                            enrolledtype = cursor1.getString(cursor1.getColumnIndex("enrolled"));

                            //Toast.makeText(getApplicationContext(), DivID, Toast.LENGTH_LONG).show();

                        }while (cursor1.moveToNext());
                    }
                }

            }

            catch(Exception e) {
                Log.e("Error", "Error", e);

            } finally {
                if (db1 != null)
                    db1.close();

            }   

            cursor1.close();  

             final Bundle bundle = new Bundle();

        enroll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {


                if((FingerImageData.getContext().toString()).equals(fingerID))
                {
                    Intent menuintent=new Intent(First.this,Menu.class);
                    bundle.putString("ThumbInfo2", FingerImageData.toString());                 
                    menuintent.putExtras(bundle);
                    startActivity(menuintent);

                }  
                /*else if((FingerImageData.getContext().toString()).equals(fingerID) && AndroidId.equals(DivID)  )
                    {
                        Intent menuintent=new Intent(First.this,Menu.class);
                        startActivity(menuintent);

                    } */
                else 
                {

                    values.put("template", FingerImageData.getContext().toString());
                    values.put("enrolled", getEnrolledType());
                    values.put("DeviceID", AndroidId.getBytes().toString() );
                    db.insert("tbl_finger", "Id", values);


                    bundle.putString("ThumbInfo1", FingerImageData.toString());                     
                    Intent enroll=new Intent(First.this,Enroll.class);
                    enroll.putExtras(bundle);
                    startActivity(enroll);                      

                }

            }

            private String getEnrolledType() {
                // TODO Auto-generated method stub
                //AndroidId.equals(DivID) && 
                if((FingerImageData.getContext().toString()).equals(fingerID)){
                    return "N";

                }
                else {
                    return "Y";
                }

            }
        });  

    }


    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.first);         

    }

}

在这里B类错误: -

here the error in class B:-

推荐答案

您不能活动之间传递的观点。您应该使用额外在你的新活动再次通过图像的位置在意向并加载它。

You shouldn't be passing views between activities. You should use extras to pass the location of the image in the intent and load it again in your new activity.

例如:

    Intent intent = new Intent(context, MyActivity.class);
    intent.putExtra("imagePath", pathToImage);
    startActivity(intent);

而在你收到的活动:

And in you receiving activity:

    String path = getIntent().getStringExtra("imagePath");
    Drawable image = Drawable.createFromPath(path);
    myImageView.setImageDrawable(image);

这篇关于我如何可以通过在Android的活动之间的图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆