我正在尝试用函数创建程序。
代码非常简单,但我在java中苦苦寻找基本语法。
OnClickListener voiceListener = new OnClickListener() {
public void onClick(View v) {
FA();//I want FB is operated after FA and onActivityResult are finished..
FB();
}
};
private void FA(){...startActivityForResult(intent,check);
}
private void FB(){}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == check && resultCode == RESULT_OK){
results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
}
super.onActivityResult(requestCode, resultCode, data);
}
}
// 问题是,当我点击按钮时,FA和FB一起操作,看起来像FA,FB 我想看到的是,在执行FA(意图通过)后,程序进入onActivityResult并将结果应用于FB。 这样做我应该在哪里触摸?我该怎么办? 我期待看到意见! :)
答案 0 :(得分:0)
在onActivityResult方法中执行FB()方法的操作,就像这样
OnClickListener voiceListener = new OnClickListener() {
public void onClick(View v) {
FA();//I want FB is operated after FA and onActivityResult are finished..
//Don't call FB over here
}
};
//FA method defined here which startActivityForResult
private void FA(){...startActivityForResult(intent,check);
}
//FB method defined here
private void FB(){}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == check && resultCode == RESULT_OK){
results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
//Call FB over here
FB();
}
super.onActivityResult(requestCode, resultCode, data);
}
}
我希望这会有所帮助。还有疑惑吗?评论如下。