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

  • SEARCH
  • Home
  • 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 8033747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:47:47+00:00 2026-06-05T01:47:47+00:00

I have an app with a list view. The listview works fine. The problem

  • 0

I have an app with a list view. The listview works fine. The problem starts, when I want the list to start with some of the rows marked. I can mark a row, if I press on it. But, don’t seem to find a way to mark any row on initialization.

This is my code:

listViewOfBluetooth = getListView();
setInitialEnabledDevices();
  listViewOfBluetooth.setOnItemClickListener(new OnItemClickListener() {

  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      String chosenBluetoothDevice = (String) ((TextView) view).getText();

      BluetoothEnableOrDisable(view, chosenBluetoothDevice);
      Toast.makeText(getApplicationContext(), chosenBluetoothDevice, Toast.LENGTH_SHORT).show();
      editor.putString("bluetooth_name_from_list1", chosenBluetoothDevice);
      editor.putBoolean("have_the_cars_bluetooth", true);
      editor.commit();
      Intent intent = new Intent(List.this, ParkOGuardActivity.class);
      startActivity(intent);
      }
  });
}

public static void setInitialEnabledDevices(){
    int length = listViewOfBluetooth.getChildCount();
    View view = null;
    String first = prefs.getString("bluetooth_name_from_list0", "");
    String second = prefs.getString("bluetooth_name_from_list1", "");
    String third = prefs.getString("bluetooth_name_from_list2", "");
    for(int i = 0; i < length; i++){
        view = listViewOfBluetooth.getChildAt(i);
        if(view.equals(first) || view.equals(second) || view.equals(third)) {
            view.setBackgroundColor(Color.GRAY);
        }
    }       
}

How can I fix it?

Thanks!

  • 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-06-05T01:47:49+00:00Added an answer on June 5, 2026 at 1:47 am

    You can achive this by using custom adapter. Here is the workaround.

    • Initialize your custom adapter
    • Add some flag for marked device names.
    • Override the getView() & check for the flag. And set the background of the list item accordingly.

    Reply if you don’t get it or face any complexity.

    Update:

    Here is a sample adapter. I didn’t compile the code. So there might be some errors.

    import java.util.ArrayList;
    
    import android.content.Context;
    import android.graphics.Color;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.TextView;
    
    public class TestAdapter extends BaseAdapter
    {
        ArrayList<String> deviceNames;
        ArrayList<Boolean> selected;
        Context context;
    
        public TestAdapter(Context context)
        {
            this.context = context;
            deviceNames = new ArrayList<String>();
            selected = new ArrayList<Boolean>();
        }
    
        public void addDeviceToList(String deviceName, boolean isSelected)
        {
            deviceNames.add(deviceName);
            selected.add(isSelected);
            notifyDataSetChanged();
        }
    
        public int getCount()
        {
            return deviceNames.size();
        }
    
        public Object getItem(int position)
        {
            return deviceNames.get(position);
        }
    
        public long getItemId(int position)
        {
            return position;
        }
    
        public View getView(int position, View convertView, ViewGroup parent)
        {
            TextView tv = new TextView(context);
            tv.setText(deviceNames.get(position));
            if(selected.get(position) == true)
            {
                tv.setBackgroundColor(Color.parseColor("#ff0000"));
            }
            return tv;
        }
    }
    

    Now create adapter object and set the adapter to listView. And add single item by calling addDeviceToList() method.

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

Sidebar

Related Questions

In my app I have a Custom listview with some textviews and Image view
I have a list view in my app which shows 10 items initially, and
I have developed an Andriod RSS reader app.I have used custom listview to list
I have a problem saving the list after edit the listview with drag and
I have a list view and when item in the listview clicked, I save
I have a long ListView which contains a list of actions which my app
I have an Android app with a ListView, and each row in the list
I have an app using a ListView as a main screen. Each row displays
In my app i have a ListView which dynamically increases by adding 10 items
I have a WPF App that implements a ListView. I would like to show

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.