我想通過我的view
在其他活動中更新我的view
。這是我通過view
的代碼。以意圖傳遞視圖
emp_photo_edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
i.putExtra("container", (Serializable) viewDialog);
((EmployeeActivity)context).startActivityForResult(i, 2017);
}
});
然後我想更新我的觀點在其他活動
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 2017 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
View apa = (View) data.getSerializableExtra("content");
//View dialog = View.inflate(getApplicationContext(),R.layout.dialog_employee_edit,null);
ImageView imageView = (ImageView) apa.findViewById(R.id.emp_photo_edit);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}
但它顯示出異常。
FATAL EXCEPTION: main
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to java.io.Serializable
at com.fingerspot.hz07.revocloud.adapter.EmployeeAdapter$MyViewHolder$5.onClick(EmployeeAdapter.java:334)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
意見不能從一個'Activity'傳遞到另一個。 –