[英]click a button inside onActivityResult() after capturing an image from camera in android app
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
//Button Click
}
}
}
Here if the RESULT_OK,how to click a button and do whatever we want. 如果是RESULT_OK,如何单击按钮并执行我们想要的任何操作。 Please Help me to find the solution.I have used if(getTaskId()==R.id.PassImageBtn){}
but nothing is happening if I click on the Button. 请帮助我找到解决方案。我已经使用过if(getTaskId()==R.id.PassImageBtn){}
但是如果单击Button则什么也没有发生。
Use performClick () method to the call button click event. 使用performClick ()方法调用按钮的单击事件。
private Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_layout);
mButton = findViewById(R.id.my_button);
mButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// ...
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == PICK_CONTACT_REQUEST) {
// Make sure the request was successful
if (resultCode == RESULT_OK) {
mButton.performClick();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.