Notification Popup Occurs in Quadruplicate

My question exceeds the limitations of the title, so I'll elaborate here. I am developing an app that can write and read a NDEF message on/from NFC cards when detected by a phone. The issue is that everything in the code seems to repeat itself four times.

Although "UltraLightCard Detected" and "Connected" messages only appear once, everything else within the code, including the AlertDialog box, pops up 4 times, requiring users to input text 4 times even if they only want to save it once.

Below is a snippet of my code:

protected void ultralightCardLogic() {
    final Button b_write = (Button)findViewById(R.id.b_write);
    final Button b_read = (Button)findViewById(R.id.b_read);

    b_write.setId(1);
    b_read.setId(2);
  
    ShowMessage("UltraLight Card Detected :" + mifareUL.getTagName(), 'a');

    try {
        mifareUL.connect();
        mifareUL.formatT2T();
        ShowMessage("Connected!" , 'd');
        b_write.setOnTouchListener(new MyTouchListener());
        b_read.setOnTouchListener(new MyTouchListener());
    } catch (IOException e) {
        e.printStackTrace();
    }

}

If you require more code snippets for further assistance, please let me know. Any help is greatly appreciated.

Answer №1

With the assistance you provided, I was able to resolve my issue.

I originally used onTouchListener, which resulted in multiple triggers due to the availability of more MotionEvents.

Switching to OnClickListener resolved the problem and everything now functions smoothly! Just ensure that you implement View.OnClickListener as shown in my public class MyClickListener.

Eclipse will then automatically generate the necessary code for you. Extract the button ids and include them in a switch statement (especially if following this specific method):

public class MyClickListener implements android.view.View.OnClickListener{



        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            int id = v.getId();
            switch(id){
            case 1:
                onCreateDialog();
                break;
            case 2:
                readNDEFmsg();
                break;
            case 3:



                break;

            }

        }

Once again, thank you for your help! Hopefully, this solution can benefit others as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Painting multiple objects in Java without resetting can be achieved by utilizing separate instances

Currently, I am working on initializing individual cells of 20x20px as I embark on the journey of implementing Conway's Game of Life. A unique feature allows me to paint or erase a cell when I click on the screen, depending on its state within the arr ...

Changing the color of a text box when it is disabled can be achieved through JavaScript

I'm facing an issue with the formatting of my HTML elements. Specifically, I have 2 combo boxes and one text box in which all 3 are disabled. However, when they are disabled, the background color of the text box does not match that of the combo boxes. ...

How can I ensure that Redux-saga waits for API calls to resolve instead of returning promises continuously? Is there a way to make "yield call" wait for API calls to complete?

Where I'm initiating the API request: function fetchCharacter(value){ return axios.get(`https://www.breakingbadapi.com/api/characters?name=${value}`) .then(res=>{ console.log(res.data) }) .cat ...

Get started with adding a Typescript callback function to the Facebook Login Button

I am in the process of implementing Facebook login into my Angular7 application using Typescript. Although I have successfully integrated Facebook's Login Button plugin for logging in, I am facing issues with providing a callback method to the button& ...

Highstock Highcharts showcase intricate date and time data displayed on the X-axis

Attempting to utilize a JavaScript timestamp as indicated in the documentation to apply it to the X-axis has proven to be a challenging task. Despite my efforts, I have been unable to successfully implement the date data for use with a datepicker. I have ...

Generating varying commitments from one function

I have encountered an issue where I am returning a promise from a function that is part of a $q.all array. Initially, this setup works perfectly on page load. However, the challenge arises when I need to call this function multiple times afterward to updat ...

What is the best way to deactivate buttons with AngularJS?

I have a situation where I need to disable the save button in one function and permanently disable both the save as draft and save buttons in another function using AngularJS. How can I accomplish this task with the disable functionality in AngularJS? Her ...

Adjusting the empty image source in Vue.js that was generated dynamically

Currently experimenting with Vue.js and integrating a 3rd party API. Successfully fetched the JSON data and displayed it on my html, but encountering issues with missing images. As some images are absent from the JSON file, I've saved them locally on ...

Clustering JSON documents with the power of Machine Learning

Looking to conduct document clustering using JSON String data containing various key-value pairs of String and Number types. The goal is to cluster documents based on similar types of keys and values. For example, consider the following JSON Document: {" ...

How can we modify this function to interpret multiple selections at once?

For the task of displaying multiple selections from a scrolling list to an alert, I have implemented the following function: var toppings = ""; function displaySelectedToppings() { var topList = document.getElementById('to ...

Guide to invoking an API in Next.js 13 by utilizing specific variables within a client component

I currently have a collection of products that are accessible on my website through a straightforward function within a server component. async function getData() { const res = await fetch(`${apiPath}`); const data = (await res.json()) as PackProps ...

`quill-emoji : The emoji fails to render properly`

Attempting to integrate quill-emoji with ngx-quill, but struggling to display the emojis in the pop-up or once inserted. It seems like a CSS inclusion may be missing (not mentioned in the documentation on GitHub). Check out this StackBlitz showcasing the ...

Tips for monitoring user interactions with buttons in a React JS Android app using Firebase?

I am a novice when it comes to react native apps and I am currently exploring how to track specific buttons within my android application. Within my react native app, there is a "submit" button that appears during the signup process, and I am looking to t ...

The functionality of an Ajax call is limited to a single use, regardless of using

For the past couple of weeks, I've been struggling to get my Ajax call to function more than once. As a self-taught individual, I've been trying my best to troubleshoot this issue on my own, but it's really getting to me. Some others facing ...

How can a node be added between two nodes based on an attribute condition?

Is there a jQuery function, or perhaps another library function, that allows for the insertion of a node (div) between two other nodes (divs) based on its attribute? For instance: Assume I have the following HTML code: <div value=111/> <div val ...

Error MSB3073 in Visual Studio 2015 CTP when trying to build Android with ant.bat

I'm encountering an issue while trying to build my APK using MSVC 2015. Do you think the problem might be related to the build pipeline? Any suggestions? 2>------ Build started: Project: NativeApp1.Packaging, Configuration: Debug ARM ------ 2&g ...

What could be the reason for my reset function not halting?

Why does my reset button keep clearing the canvas and emptying the chat box even though the return statement is supposed to end the function? Main.js var reset = function() { context.clearRect(0,0, canvas[0].width, canvas[0].height); context.be ...

Delete the AsyncListDiffer list and make sure to refresh it after closing the search (submitting null does not work)

Using AsyncListDiffer in this application, there is a toolbar with a searchBar and a search icon. The goal is to replace the old search list with a new one when the user closes the search and submits a new request. Despite calling submitList(null), the new ...

The most effective method to verify if the Selenium WebDriver has terminated in Java

Looking to verify if the quit() method has been called on the WebDriver for a collection of Page Objects. A method has been created to check the state of a WebDriver: public static boolean hasQuit(WebDriver driver) { try { driver.getT ...

Comparison of Saving JSON Data on Android: SQLite or SharedPreference

Looking to develop an application for members of my organization to access data on their mobile devices, I require a method to store pre-formatted data locally so it can be viewed offline. The data will be fetched using a JSON request-response. The respon ...