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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:41:21+00:00 2026-06-13T12:41:21+00:00

Here in my application I want to create the list view with toggle button

  • 0

Here in my application I want to create the list view with toggle button and text view. when I am clicking on the list item I want to go next Activity. But when I am clicking on the Toogle button I need to display it is in off mode or on mode. below I add my code.

$
This is my main activity

public class MainActivity extends Activity {

    int startminute;
    int endminute;

    Date date;
    ToggleButton togg;
    ListView lv;
    String[] days = { "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY",
            "FRIDAY", "SATURDAY" };
    boolean[] onOff = new boolean[] { false, false, false, false, false, false,
            false };

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        if (savedInstanceState != null) {
            onOff = savedInstanceState.getBooleanArray("status");
        }
        lv = (ListView) findViewById(R.id.listView1);
        lv.setAdapter(new MyAdapter());
        lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {

                Intent in = new Intent(MainActivity.this, StartAndEndTime.class);
                in.putExtra("position", position);
                startActivity(in);
            }
        });
    }

    public class MyAdapter extends BaseAdapter {

        public int getCount() {
            return days.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        @Override
        public int getItemViewType(int position) {

            return position;
        }

        @Override
        public int getViewTypeCount() {
            return days.length;
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {
            View v = null;
            TextView arryText;

            if (v == null) {
                LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.inflate, null);

                arryText = (TextView) v.findViewById(R.id.inflateText);
                togg = (ToggleButton) v.findViewById(R.id.toggleButton1);
                v.setTag(new ViewHolder(arryText, togg));

                togg.setOnClickListener(new OnClickListener() {

                    public void onClick(View v) {

                        if (togg.isChecked()) {
                            togg.setChecked(false);
                            onOff[position] = false;

                            Toast.makeText(MainActivity.this, "is off",
                                    Toast.LENGTH_SHORT).show();

                        } else {

                            onOff[position] = true;
                            togg.setChecked(true);
                            Toast.makeText(MainActivity.this, "is on",
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });

                arryText.setText(days[position]);
                togg.setChecked(onOff[position]);
            }

            return v;
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBooleanArray("status", onOff);
}
  • 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-13T12:41:21+00:00Added an answer on June 13, 2026 at 12:41 pm

    change your getView method in this way…

    public View getView(final int position, View convertView,
            ViewGroup parent) {
        View v = null;
        TextView arryText;
    
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.inflate, null);
        }
            arryText = (TextView) v.findViewById(R.id.inflateText);
            togg = (ToggleButton) v.findViewById(R.id.toggleButton1);
            v.setTag(new ViewHolder(arryText, togg));
    
            togg.setOnClickListener(new OnClickListener() {
    
                    public void onClick(View v) {
    
                        if (onOff[position]) {
                            togg.setChecked(false);
                            onOff[position] = false;
    
                            Toast.makeText(MainActivity.this, "is off",
                                    Toast.LENGTH_SHORT).show();
    
                        } else {
    
                            onOff[position] = true;
                            togg.setChecked(true);
                            Toast.makeText(MainActivity.this, "is on",
                                    Toast.LENGTH_SHORT).show();
    
                        }
    
                    }
                });
    
            arryText.setText(days[position]);
            togg.setChecked(onOff[position]);
    
    
    
        return v;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want create a web application that display a list of items. Suppose I
In my application i have a listView. each item of the list view contains
I want to create an HIMAGELIST for the list view. It actually needs to
I want to program an application to send a file with sockets: Here my
I want to display a popup windo on my rails application... Here is exactly
I want to retrieve values from SQLite database in my Android application. Here in
I've downloaded a sample application sending email silverlight application here. via gmail. But I
...before everything, I'm doing this out of curiosity only. Nothing real-world application here, but
This is to create a greeting card application and here i have to change
I am developing an application in android in which i creating a list view

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.