有目的地传递视图 [英] Passing View with Intent
本文介绍了有目的地传递视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过我的 view
更新其他活动中的 view
.这是我要传递 view
的代码.
I want to passing my view
to update my view
in other activity. This is my code to passing 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);
}
});
然后我想在其他活动中更新视图
Then i want to update my view in other activity
@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)
推荐答案
传递给捆绑软件的参数应实现 Serializable
或 Parcelable
接口. LinearLayout
没有.最好的解决方案是将视图内的数据传递给Intent并将其应用于接收方 Activity
Arguments passed to the bundle should implement the Serializable
or Parcelable
interface. The LinearLayout
doesn't. The best solution is to pass the data inside the view to the Intent and apply that to a view in the receiving Activity
这篇关于有目的地传递视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文