在下面的代码片段中给TextView赋值有一个问题:
public class EventHandler implements RfidEventsListener {
// Read Event Notification
public void eventReadNotify(RfidReadEvents e) {
// Recommended to use new method getReadTagsEx for better performance in case of large tag population
TagData[] myTags = reader.Actions.getReadTags(2);
if (myTags != null) {
for (int index = 0; index < myTags.length; index++) {
Log.d(TAG, "Tag ID " + myTags[index].getTagID());
**textView.setText(myTags[0].getTagID());**
if (myTags[index].getOpCode() == ACCESS_OPERATION_CODE.ACCESS_OPERATION_READ &&
myTags[index].getOpStatus() == ACCESS_OPERATION_STATUS.ACCESS_SUCCESS) {
if (myTags[index].getMemoryBankData().length() > 0) {
Log.d(TAG, " Mem Bank Data " + myTags[index].getMemoryBankData());
我正在尝试分配读取标签数组的零元素的值:textView.setText(myTags[0].getTagID());
但是什么也没有发生,尽管这行运行良好,我可以看到在log cat中读取的标签id:
Log.d(TAG, "Tag ID " + myTags[index].getTagID());
我做错了什么?
是否尝试在UI线程中设置文本视图?
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(myTags[0].getTagID());
}
});