gpt4 book ai didi

android - getIntent() 类型未为适配器定义

转载 作者:行者123 更新时间:2023-11-29 15:19:27 28 4
gpt4 key购买 nike

我正在通过这样的 Intent 从另一个 Activity 中获取 byteArray:

        if (view == null) {
view = new ImageView(mContext);
}
Bundle extras = getIntent().getExtras();
byte[] byteArray = extras.getByteArray("picture");
Bitmap default_b = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
view.setImageBitmap(default_b);
view.setImageResource(drawables.get(position));
view.setScaleType(ImageView.ScaleType.CENTER_CROP);
view.setLayoutParams(new android.widget.GridView.LayoutParams(70, 70));
view.setTag(String.valueOf(position));
return view;

但我得到的错误是 getIntent() 未定义类型 GridViewAdapter(这在我的 gridView 适配器基类中)

我在这里创建 Intent :

Intent intent = new Intent(v.getContext(), GridViewAdapter.class);
intent.putExtra("picture", byteArray);
v.getContext().startActivity(intent);

我该如何修复这个错误?

添加:

这是我创建 Intent 的完整部分:

        Log.d("AppInfoAdapter", "Data Set To Display");
addCheckbox
.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if (addCheckbox.isChecked()) {
System.out.println("Checked");
PackageManager pm = mContext.getPackageManager();
Drawable icon = null;
try {
icon = pm
.getApplicationIcon(entry.activityInfo.packageName);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Drawable default_icon = pm.getDefaultActivityIcon();
if (icon instanceof BitmapDrawable
&& default_icon instanceof BitmapDrawable) {
BitmapDrawable icon_bd = (BitmapDrawable) icon;
Bitmap icon_b = icon_bd.getBitmap();
BitmapDrawable default_bd = (BitmapDrawable) pm
.getDefaultActivityIcon();
Bitmap default_b = default_bd.getBitmap();
if (icon_b == default_b) {
// It's the default icon
scaleDownBitmap(default_b, 100, v.getContext());
Log.d("AppInfoAdapter", "Scale Bitmap Chosen");

ByteArrayOutputStream stream = new ByteArrayOutputStream();
default_b.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Log.d("AppInfoAdapter", "Scale Bitmap to Array");

Intent intent = new Intent(v.getContext(), GridViewAdapter.class);
intent.putExtra("picture", byteArray);
v.getContext().startActivity(intent);
Log.d("AppInfoAdapter", "Intent started to send Bitmap");
}
}
} else {
System.out.println("Un-Checked");
}

}
});

最佳答案

将您的 Activity 上下文传递给 Adapter 构造函数

在那里你可以像这样访问你的 Intent

((Activity)mContext).getIntent()

关于android - getIntent() 类型未为适配器定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19967506/

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