android-从外部键盘输入数据时获取数据
我的平板电脑连接了蓝牙条形码扫描仪。每当我扫描条形码,并且焦点位于应用程序的编辑文本框时,扫描的数据就会出现在编辑文本中。
我想在编辑文本中同时获取这些数据。我尝试过使用 setOnClickListener
,setOnKeyListener
。如果有人知道,请告诉我。
编辑: 我遵循的步骤:
我的程序有一个简单的编辑文本、一个按钮、一个文本框。
通过硬件输入扫描条形码时,数据被插入到我的程序的编辑文本中。
单击按钮时,我将编辑文本内容复制到文本框中。
我希望我的应用程序执行以下操作:
数据出现在编辑文本中后,我想将其复制到文本框中。现在我正在通过单击按钮来完成此操作。
这是我的代码:我怀疑它是否有帮助,因为外部硬件正在编辑文本本身中显示数据。
<代码> 公共类 SimpleTextBoxActivity 扩展 Activity {
Button btnClear, btnPairedList, btnAvailableList, btnPairedAvailableList,btnShowScan;
EditText edtSacnnedData;
BroadcastReceiver brSent;
TextView txtShowScannedData;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edtSacnnedData=(EditText) findViewById(R.id.edtData);
btnClear=(Button) findViewById(R.id.btnClear);
btnShowScan=(Button) findViewById(R.id.btnScannedText);
txtShowScannedData=(TextView) findViewById(R.id.txtScanData);
Log.d("my", "b4 set visibility");
edtSacnnedData.setBackgroundColor(Color.BLACK);
Log.d("my", "after set visibility");
btnClear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
edtSacnnedData.setText("");
txtShowScannedData.setText("");
}
});
btnShowScan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String str=edtSacnnedData.getText().toString();
txtShowScannedData.setText(str);
edtSacnnedData.setText("");
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
I have a bluetooth bar code scanner connected to my tablet. Whenever i scan a barcode, and the focus is on the edit text box of my app, the scanned data appears in the edit text.
I want to take this data simultaneously as it comes in the edit text. I have tried using setOnClickListener
,setOnKeyListener
. If any one knows, please let me know.
EDITED:
Steps that I am following:
my program has a simple edit text, a button, a text box.
on scan of the barcode through a hardware input, the data is getting inserted into my program's edit text.
on click of the button, i copy the edit text contents into text box.
What I want my app to do:
As soon as the data appears in the edit text, i want to copy it into the text box. Right now I am doing it on the button's click.
Here is my code: I doubt if it's helpful, coz the external hardware is displaying the data in the edit text itself.
public class SimpleTextBoxActivity extends Activity {
Button btnClear, btnPairedList, btnAvailableList, btnPairedAvailableList,btnShowScan;
EditText edtSacnnedData;
BroadcastReceiver brSent;
TextView txtShowScannedData;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edtSacnnedData=(EditText) findViewById(R.id.edtData);
btnClear=(Button) findViewById(R.id.btnClear);
btnShowScan=(Button) findViewById(R.id.btnScannedText);
txtShowScannedData=(TextView) findViewById(R.id.txtScanData);
Log.d("my", "b4 set visibility");
edtSacnnedData.setBackgroundColor(Color.BLACK);
Log.d("my", "after set visibility");
btnClear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
edtSacnnedData.setText("");
txtShowScannedData.setText("");
}
});
btnShowScan.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String str=edtSacnnedData.getText().toString();
txtShowScannedData.setText(str);
edtSacnnedData.setText("");
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 addTextChangedListener(..) 可能对您有帮助。这是对此进行有趣讨论的链接。 文本更改侦听器
You need to use addTextChangedListener(..) may be helpful for you. Here is link for interesting discussion on this. Text changed listener
尝试在您的类中找到 editText.setText(data) 代码。
无论该 editText 的 setText() 方法的括号中是什么,这都是您的数据,您可以从这里使用它。
如果我的假设是错误的,请分享您的代码。
Try to find that editText.setText(data) code in your class.
Whatever will be in your parenthesis of setText() method of that editText, that is your data and you can use it from here.
If my assumption is wrong, please share your code.
为您的 UI 设计提供一些 id 并开始工作。我给你看一个例子。
在上面的示例中,一旦您移动焦点,您的文本视图就会更新,否则您也可以使用:
这只是一个示例。您可以提供自己的 ID 和名称。
Give some id's to your UI design and do the work. I'm showing you an example.
In the above example as soon as you move your focus your textview will be updated or else you can also use:
This is just an example. You can give your own id's and names.