gpt4 book ai didi

android - 使用带有 Tab 的 Activitygroup 未显示第二个 Activity

转载 作者:行者123 更新时间:2023-11-29 17:56:38 25 4
gpt4 key购买 nike

在我的应用中,我使用 Tab。共有三个选项卡。其中第三个选项卡是具有两个 Activity 的 Activity 组。在第一个 Activity 中,用户有两个选项。用户可以从相机或图库中选择图像。选择图像后,用户应移至子 Activity ,该 Activity 将在该 Activity 中显示所选图像。下面是我的代码...

public class GalleryPic extends Activity {

private static final int TAKE_PICTURE = 0;
private static final int REQUEST_ID = 1;
private static final int HALF = 2;
private Uri mUri;
private Bitmap mPhoto;
ImageView ivGallery, ivCamera;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_pic);
ivGallery = (ImageView)findViewById(R.id.gallery);
ivCamera = (ImageView)findViewById(R.id.snap);

ivGallery.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
Intent in = new Intent(getParent(), GalleryPic_Second.class);
TabGroupActivity parent = (TabGroupActivity) getParent();
parent.startChildActivity("ArrowsActivity", in);
startActivityForResult(intent, REQUEST_ID);

}
});

ivCamera.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
File f = new File(Environment.getExternalStorageDirectory(), "photo.jpg");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
mUri = Uri.fromFile(f);
Intent in = new Intent(getParent(), GalleryPic_Second.class);
TabGroupActivity parent = (TabGroupActivity) getParent();
parent.startChildActivity("ArrowsActivity", in);
startActivityForResult(i, TAKE_PICTURE);
}
});


}




public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case TAKE_PICTURE:
if (resultCode == Activity.RESULT_OK)
{
getContentResolver().notifyChange(mUri, null);
ContentResolver cr = getContentResolver();

Intent previewMessage = new Intent(getParent(), GalleryPic_Second.class);

TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity("ArrowsActivity", previewMessage);

try
{
mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
Intent in = new Intent(getParent(), GalleryPic_Second.class);
GalleryPic_Second.bmp = mPhoto;
TabGroupActivity parent = (TabGroupActivity) getParent();
parentActivity.startChildActivity("ArrowsActivity", in);

}

catch (Exception e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}


}


break;
case REQUEST_ID :
InputStream stream = null;
if (resultCode == Activity.RESULT_OK) {

try
{
stream = getContentResolver().openInputStream(data.getData());
Bitmap original = BitmapFactory.decodeStream(stream);
Intent in = new Intent(getParent(), GalleryPic_Second.class);
GalleryPic_Second.bmp = Bitmap.createScaledBitmap(original, original.getWidth()/HALF, original.getHeight()/HALF, true);
TabGroupActivity parent = (TabGroupActivity) getParent();
parent.startChildActivity("ArrowsActivity", in);
}

catch (Exception e)
{
e.printStackTrace();
}
if (stream != null) {
try {
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}



}


}
}


@Override
public void onBackPressed() {
// this.getParent().onBackPressed();
TabViewLayout parentTab = (TabViewLayout) this.getParent();
parentTab.switchTabBar(1);

}

}

我在这里面临的是,我没有在子 Activity 组中选择图像。我已经搜索过它并找到了这个解决方案... OnActivityResult is not working in TabActivityGroup?但我没有得到此链接中给出的解释。需要做什么?

最佳答案

您好,将您的 ActivityResult 代码放在 GroupActivity 中意味着在父级中,因为它将值返回给它的父级而不是子级。

 public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
}
}

上面的代码放在 Activity 组中。我希望它对你有用,因为它对我有用,祝你好运:-)。

关于android - 使用带有 Tab 的 Activitygroup 未显示第二个 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18847812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com