我在片段中添加了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在你的片段 –