我正在尝试在复选框的 onClick 方法中使用意图,但我收到错误,即方法 startActivity 未定义并且构造函数 Intent(new View.OnClickListener ect..) 也未定义。这是我的代码:
final CheckBox addCheckbox = (CheckBox) v
.findViewById(R.id.addCheckbox);
// set data 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.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
ByteArrayOutputStream stream = new ByteArrayOutputStream();
default_b.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Intent intent = new Intent(this, GridView.class);
intent.putExtra("picture", byteArray);
this.startActivity(intent);
}
}
} else {
System.out.println("Un-Checked");
}
}
});