合計3の活動があります。 1.アクティビティにはレコードとエントリが含まれます。 2.アクティビティ、QRコードスキャンおよびリターンデータ アクティビティ3はアクティビティ2からデータを受信します。QRコード読み取り後に活動がロックされています
スクリプトは次のようになります。ログイン後、ユーザーIDでqrcodeを読み取ることができます。読んだ後、Intent.PutExtraを使って3番目のアクティビティに関連するデータを送信したいと思います。
問題:
QRコードを読み取り前に第三の活動を開くことができますが、3番目の活動は読書後開くとエラーになりません。他のボタンでも機能しなくなります。
プログラムを連続して処理したいときに再コンパイルする必要があります。
私はQRコードスキャンにZxingライブラリを使用します。
その他の問題: QRコードを読んだ後、それは私が、問題が何であるかを理解していない活動2.
に行かなくても活動1に行きます。私のコードの
すべて:
ActivityUserProfile
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.batuhan.qrcodereader.ActivityUserProfile"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp">
</Relativelayout>
ActivityUserProfile.class
public class ActivityUserProfile extends AppCompatActivity {
private ZXingScannerView scannerView;
public static final String LOGIN_URL = "http://www.HHH.com/QR_Users_Select.php";
public static final String KEY_USERNAME = "username";
public static final String KEY_PASSWORD = "password";
private TextView txt_ViewUsername;
public static EditText edt_Productname;
public static EditText edt_Productcode;
public static EditText edt_Productweight;
public static EditText edt_Productprice;
private Button btn_addToCart;
private Button btn_Scan;
private Button btn_seeProd;
String resultCode;
public String prodName;
public String prodCode;
public String prodWeight;
public String prodPrice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_profile);
txt_ViewUsername = (TextView) findViewById(R.id.txt_ViewUsername);
edt_Productname = (EditText) findViewById(R.id.edt_ProdName);
edt_Productcode = (EditText) findViewById(R.id.edt_ProdCode);
edt_Productweight= (EditText) findViewById(R.id.edt_ProdWeight);
edt_Productprice = (EditText) findViewById(R.id.edt_ProdPrice);
edt_Productcode.setEnabled(true);
edt_Productname.setEnabled(true);
edt_Productweight.setEnabled(true);
edt_Productprice.setEnabled(true);
Intent i = getIntent();
txt_ViewUsername.setText("Sayın "+ i.getStringExtra(ActivityUserProfile.KEY_USERNAME) +" marketimize hoşgeldiniz.");
btn_Scan = (Button) findViewById(R.id.btn_scan);
btn_Scan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
scanCode();
}
});
btn_seeProd = (Button) findViewById(R.id.btn_seeProd);
btn_seeProd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),ProductView.class);
startActivity(intent);
}
});
btn_addToCart = (Button) findViewById(R.id.btn_addToCart);
btn_addToCart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
...
}
});
}
public void scanCode()
{
scannerView = new ZXingScannerView(this);
scannerView.setResultHandler(new ZXingScannerResultHandler());
setContentView(scannerView);
scannerView.startCamera();
}
@Override
public void onPause(){
super.onPause();
if (scannerView != null) {
scannerView.stopCamera();
scannerView = null;
}
}
public class ZXingScannerResultHandler implements ZXingScannerView.ResultHandler
{
@Override
public void handleResult(Result result){
try{
resultCode = result.getText();
Log.i("Bilgi","ResultCode -> "+resultCode);
setContentView(R.layout.activity_user_profile);
scannerView.removeAllViews();
scannerView.stopCamera();
String [] chars = resultCode.split(":");
Log.i("counter",chars.length+"");
Log.i("company",chars[1]);
prodName = chars[1];
prodCode = chars[3];
prodWeight =chars[5];
prodPrice = chars[7];
EditText product_name_text = (EditText) findViewById(R.id.edt_ProdName);
EditText product_code_text = (EditText) findViewById(R.id.edt_ProdCode);
EditText product_weight_text= (EditText) findViewById(R.id.edt_ProdWeight);
EditText product_price_text = (EditText) findViewById(R.id.edt_ProdPrice);
product_name_text.setText(prodName);
product_code_text.setText(prodCode);
product_weight_text.setText(String.valueOf(prodWeight));
product_price_text.setText(String.valueOf(prodPrice));
} catch (NullPointerException nu) {
Toast.makeText(ActivityUserProfile.this,"Gelen data düzenli değil!",Toast.LENGTH_LONG).show();
} catch (Exception ex){
Toast.makeText(ActivityUserProfile.this,"Okuyucuda problem oluştu!",Toast.LENGTH_LONG).show();
Log.e("errors",ex.getMessage());
}
}
}