我在片段中添加了onClick()
按钮以显示结果。我还在MyActivity
中加入了onActivityResult()
方法。我想在更多片段中添加onClick()
按钮并显示结果。Android中的多重OnactivityResult方法
在这种情况下,我应该如何在活动中编写多个onActivityResult()
方法?
下面是我对OnActivityResultmethod
代码:
button = (Button) view.findViewById(R.id.zing);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator scanIntegrator = new IntentIntegrator(getActivity());
scanIntegrator.initiateScan();
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
//super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode,
data);
Fragment fragment = this.getFragmentManager().findFragmentById(R.id.total_frame_content);
if (fragment instanceof CustomerIdFragment) {
if (scanResult != null) {
if (scanResult.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
} else {
//String customerSno = scanResult.getContents().substring(0, 10),
// passCode = scanResult.getContents().substring(10, 14);
Toast.makeText(this, " " + scanResult.getContents(), Toast.LENGTH_SHORT).show();
// System.out.println("Result" + scanResult.getContents());
}
}
}
}
android geeks ...我是初学者到android..where我应该调用startActivityForResult(intent,1);和我的Onclik代码片段.... button =(Button)view.findViewById(R.id.zing); button.setOnClickListener(new View。OnClickListener(){ @Override public void onClick(View v){ IntentIntegrator scanIntegrator = new IntentIntegrator(getActivity()); scanIntegrator.initiateScan(); } });像这样 – Kingraj
@Kingraj对不起,我不明白你想做什么? –
如果你想开始活动的结果u也可以从你的按钮调用它,你也可以overActivityResult在你的片段 –