This is my code. What should I change or add to go to another layout? I am doing QR code scanner ,I am trying to do when it scan if the code is “1234” it will go to the new layout name is 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);
}
}
}
The easiest way is to nest both main and abcd in a FrameLayout. FrameLayout is a stack of child views and can show one of them at a time.
Here is a sample portion of a layout that would utilize a FrameLayout and reuse your existing layouts:
Then in onCreate, find abcd and set its visibility to View.INVISIBLE:
When your barcode equals 1234, then do something like: