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 7943609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:19:09+00:00 2026-06-04T00:19:09+00:00

i’m new to Android platform, but not to java. Problem: Everytime i select ToggleButton,

  • 0

i’m new to Android platform, but not to java.

Problem:

Everytime i select ToggleButton, whitch is in ArrayAdapter, more then one ToggleButton is selected.

private Context context;
private List<DayListItem> list;

public DayListAdapter(Context context, List<DayListItem> objects) {
    super(context, R.layout.day_row, objects);
    this.context = context;
    this.list = objects;
}

@Override
public int getPosition(DayListItem item) {
    return list.indexOf(item);
}

@Override
public int getCount() {
    return list!=null?list.size():0;
}

static class ViewHolder{
    protected RelativeLayout rl;
    protected TextView position;
    protected TextView time;
    protected TextView info;
    protected ToggleButton button;
}

@Override
public DayListItem getItem(int position) {
    return list.get(position);
}

@Override
public long getItemId(int position) {
    return list.get(position).getID();
}

@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
    View view = convertView;
    final ViewHolder viewHolder;
    if(view == null){
        LayoutInflater inflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflate.inflate(R.layout.day_row, null);
        viewHolder = new ViewHolder();
        viewHolder.rl = (RelativeLayout) view.findViewById(R.id.alarmCLICK);
        viewHolder.position = (TextView) view.findViewById(R.id.alarmPOSITION);
        viewHolder.time = (TextView) view.findViewById(R.id.alarmSETtime);
        viewHolder.info = (TextView) view.findViewById(R.id.alarmINFO);
        viewHolder.button = (ToggleButton) view.findViewById(R.id.alarmTOGGLE);

        view.setTag(viewHolder);
    }else{
        viewHolder = (ViewHolder) view.getTag();
    }
    viewHolder.time.setText(list.get(position).getTime());
    viewHolder.info.setText(list.get(position).getInfo());
    viewHolder.position.setText(String.valueOf(position));
    viewHolder.button.setSelected(list.get(position).isSelected());
    viewHolder.rl.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Dialog dialog = new Dialog(v.getContext());
            dialog.setContentView(R.layout.alarm_list);
            dialog.setTitle(String.valueOf(position));
            dialog.setCancelable(true); 
            dialog.show();
        }
    });
    viewHolder.button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if(viewHolder.button.isChecked()){
                Log.w("position",String.valueOf(position));
                list.get(position).setSelected(true);
            }else list.get(position).setSelected(false);
        }
    });     
    return view;
}

I don’t know why it seams that ToggleButtons are redrawned every time i move the list.

  • 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-04T00:19:10+00:00Added an answer on June 4, 2026 at 12:19 am

    You are using custom adapter. Here i am writing solution use this it will solve your problem. I have also faced same problem from checkboxes. Try this. First save state of your toggle button into array list.

    private ArrayList toggle_state = null;

    Then I will set states of all as false in custom adapter constructor:

    for (int i=0; i < no_of_elements.size(); i++) {
        itemChecked.add(i, false);
    }
    

    Set the actual toggle state when button clicked:

        holder.cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                itemChecked.set(position, isChecked);
    
            }
        });
    

    where cb is toggle button.

    In your getView method of your custom adapter write:

    holder.cb.setChecked(itemChecked.get(position));
    

    this will solve your problem.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.