0

I know how to add a ToggleButton to ALL of the listView rows. But how do i add a ToggleButton to only ONE specific listView row?

Im populating my listView with an ArrayAdapter like so

ListView mlistView = (ListView) findViewById(R.id.listViewSetting);
mlistView.setAdapter(new ArrayAdapter<String>(this,
          android.R.layout.simple_list_item_1,
          new String[] {"Rate @ME App", "Feedback", "Block", "Terms of Service", "Push Notifications", "Sign Out"}));

1 Answer 1

2
  1. Create a layout file containing a togglebutton
  2. Create a customAdapter by extending an Adapter e.g. ArrayAdapter
  3. Override the getView() method
  4. Implement the viewHolder pattern to improve performance
  5. Add logic to the getView() method to handle the togglebutton

Here is some pseudocode

    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
         // Do inflation here, use a viewholder pattern to improve performance

         // Add logic to handle togglebutton, view being togglebutton
         if(items.get(position).equals(something){
            view.setVisibilty(View.Visible);
         }else{
             view.setVisibilty(View.GONE);
         }
     }
Sign up to request clarification or add additional context in comments.

2 Comments

Im a little confused on number 2. Create a customAdapter by extending an Adapter e.g. ArrayAdapter Im coming over from iOS if that helps any. And i understand the concept of what your saying. Just confused on number 2, and a little on 4 but ive seen a few topics on that and can understand that as well.
If have added a link to a tutorial (this tutorial covers most of the points mentioned), hope this clears it up for you, if not comment below

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.