您好我有一个edittext和一个按钮。
我希望当用户通过按下要输入的号码输入号码并在索引倒数第二个号码上下注时。 基本上,我该怎么办?谢谢。
我尝试使用以下代码执行此操作:
public class BarcodScanner extends AppCompatActivity implements OnClickListener {
private Button scanBtn;
private Button nextLevel;
private EditText formatTxt, contentTxt;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scanner);
scanBtn = (Button)findViewById(R.id.scan_button);
nextLevel =(Button)findViewById(R.id.btn_enter);
textView = (TextView) findViewById(R.id.view1);
formatTxt = (EditText) findViewById(R.id.scan_format);
contentTxt = (EditText) findViewById(R.id.scan_content);
nextLevel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String inn = formatTxt.getText().toString();
int length_s = inn.length();
char m = inn.charAt(length_s - 2);
if ( m == 1){
Toast.makeText(BarcodScanner.this, "قبض آب",Toast.LENGTH_LONG).show();
}
}
});
scanBtn.setOnClickListener(this);
}
public void onClick(View v){
if(v.getId()==R.id.scan_button){
IntentIntegrator scanIntegrator = new IntentIntegrator(this);
scanIntegrator.initiateScan();
}
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanningResult != null) {
String scanContent = scanningResult.getContents();
if (scanContent != null) {
formatTxt.setText(scanContent.substring(0, 13));
contentTxt.setText(scanContent.substring(18));
}
}
else{
Toast toast = Toast.makeText(getApplicationContext(),
"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
}