このレイアウトでは、例えば10回のスキャンの後、「Scan qr」ではなく「send email」と言い、クリックすると別のアクティビティ(またはその他の動作)を開くようにします。どうすればいいのか説明してください。実行中にボタンのプロパティを変更したい(ボタンのテキスト、クリックの動作例)。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_scan"
android:background="@color/mybackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.android.sdemo.ScanActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Scanning QR"
style="@style/myHeading"
android:layout_gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/mySubHeading"
android:id="@+id/scan_tips"
android:text="@string/scan_tips"/>
</LinearLayout>
<Button
android:text="Scan QR"
android:layout_width="match_parent"
style="@style/myButton"
android:id="@+id/button_start_scan"
android:onClick="onClick"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
javaファイル
package com.example.android.sdemo;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.google.zxing.Result;
import me.dm7.barcodescanner.zxing.ZXingScannerView;
public class ScanActivity extends Activity implements ZXingScannerView.ResultHandler{
private ZXingScannerView mScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
mScannerView = new ZXingScannerView(this);
}
public void onClick(View v){
setContentView(mScannerView);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
}
@Override
protected void onPause() {
super.onPause();
mScannerView.stopCamera();
}
@Override
public void handleResult(Result result){
// Toast.makeText(getApplicationContext(), result.getText(), Toast.LENGTH_SHORT).show();
Intent intentBack = new Intent(getApplication(), StoryActivity.class);
intentBack.putExtra("qrResult", result.getText());
startActivity(intentBack);
//mScannerView.resumeCameraPreview(this);
}
}