Nikolai
Nikolai

Reputation: 17

Can't set array value with TextView.SetText

there is a problem with assigning values ​​to the TextView in the following code snippet:

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());
                      

I am trying to assign the value of the zero element of an array of read tags: textView.setText(myTags[0].getTagID());

But nothing happens, although this line works fine and I can see the IDs of the tags read in log cat:

Log.d(TAG, "Tag ID " + myTags[index].getTagID());

What am I doing wrong?

Upvotes: 1

Views: 219

Answers (1)

mohammed ahmed
mohammed ahmed

Reputation: 305

Did you tried setting the text view in UI Thread?

     getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            textView.setText(myTags[0].getTagID());
            }
        });

Upvotes: 2

Related Questions