Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:36:59+00:00 2026-05-24T23:36:59+00:00

I’m trying to create an image button that, when pressed, presents the users a

  • 0

I’m trying to create an image button that, when pressed, presents the users a list of Paired Bluetooth devices to connect to.

However, I get “Set cannot be resolved as a variable” at point ##1,
and “mArrayAdapber cannot be resolved” at point ##2
(##1 and ##2 are not part of the code…)

I used the code from the Android site, but being in the dark, I find myself in the dark.

I’d appreciate some guidance…

//Search

ImageButton bSearch = (ImageButton) findViewById(R.id.Search);
bSearch.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {                        
        ##1Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
        // If there are paired devices
        if (pairedDevices.size() > 0) {
            // Loop through paired devices
            for (BluetoothDevice device : pairedDevices) {
                // Add the name and address to an array adapter to show in a ListView
                ##2mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }
        }                                                                           
    }                       
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:36:59+00:00Added an answer on May 24, 2026 at 11:36 pm

    For 1) Well if you haven’t done so , add

    > import java.util.Set;

    in your import statements . This will resolve “Set” error.

    For 2) Declare and initialize

    mArrayAdapter

    For example in your Activity do :

    private ArrayAdapter<String> mArrayAdapter;
    

    and then on onCreate:

     mArrayAdapter= new ArrayAdapter<String>(this, <your layout file>);
    

    which should then be added to a ListView

    // Find and set up the ListView for newly discovered devices

       ListView newDevicesListView = (ListView)
     findViewById(R.id.<layout_file>);
             newDevicesListView.setAdapter(mArrayAdapter);
    
     newDevicesListView.setOnItemClickListener(mDeviceClickListener);
    

    Refer to Bluetooth Chat example from Android examples. It should help you get going with the Bluetooth api’s


    Update on comment :

    If you look closely on BluetoothChat.java file in BT example, you’ll see this

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(D) Log.d(TAG, "onActivityResult " + resultCode);
            switch (requestCode) {
            case REQUEST_CONNECT_DEVICE:
                // When DeviceListActivity returns with a device to connect
                if (resultCode == Activity.RESULT_OK) {
                    // Get the device MAC address
                    String address = data.getExtras()
                                         .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS);
                    // Get the BLuetoothDevice object
                    BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
                    // Attempt to connect to the device
                    mChatService.connect(device);
                }
                break;
            case REQUEST_ENABLE_BT:
                // When the request to enable Bluetooth returns
                if (resultCode == Activity.RESULT_OK) {
                    // Bluetooth is now enabled, so set up a chat session
                    setupChat();
                } else {
                    // User did not enable Bluetooth or an error occured
                    Log.d(TAG, "BT not enabled");
                    Toast.makeText(this, R.string.bt_not_enabled_leaving, Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        }
    

    Watch this line :

     // Attempt to connect to the device
     mChatService.connect(device);
    

    This function connects to bluetooth device. First time it’ll ask you to pair it automatically. Once paired, next time it’ll auto connect to the bluetooth device.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.