在扩展View而不扩展AppCompatActivity的类中使用startActivityForResult方法



如何在扩展View而不扩展AppCompatActivity的类中使用startActivityForResult方法?

public class ContentsElement extends View {

public ContentsElement(final Context context, final String text, final int requestCode, FlexboxLayout cl) {
super(context);
final TextView mu = new TextView(getContext());
mu.setText(text);
cl.addView(mu);
mu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast toast = Toast.makeText(getContext(),
mu.getText(), Toast.LENGTH_SHORT);
toast.show();
Context context = getContext();
Intent i = new Intent(context, MainActivity.class);
startActivityForResult(i, requestCode);
}
});

}

}

用修复startActivityForResult(i, requestCode);

((Activity)context).startActivityForResult(i, requestCode);

相关内容

  • 没有找到相关文章

最新更新