这是我的代码。我应该更改或添加什么以转到另一个布局?我正在做 QR 码扫描仪,当它扫描时,如果代码为“1234”,它将转到新的布局名称为 abcd.xml。
package wj.com;
import android.app.Activity;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class OCTotActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick (View view){
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
// handle scan result
String barcode;
barcode = scanResult.getContents();{
if (barcode.equals("1234")){
setContentView(R.layout.abcd);
}
}
EditText etBarcode = (EditText) findViewById(R.id.etBarcode);
etBarcode.setText(barcode);
}
}
}