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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:34:33+00:00 2026-06-10T14:34:33+00:00

I am writing an application something like list view with toggle button. Here is

  • 0

I am writing an application something like list view with toggle button.
Here is my source code.

   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),R.layout.main,R.id.textView1,getResources().getStringArray(R.array.Strings));
     setListAdapter(adapter);

   }

 @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
  String item = (String) getListAdapter().getItem(position);
  Toast.makeText(this, item+" selected", Toast.LENGTH_LONG).show();
}

And I am importing the list from string resources, and my sring.xml is

MyListViewWithToggleButton
Hello world!
Settings
MyListViewWithToggle
ON/OFF

  <string-array name="Strings">

   <item >Relay1</item>
  <item >Relay2</item>
  <item >Relay3</item>
  <item >Relay4</item>
  <item >Relay5</item>
  <item >Relay6</item>
  <item >Relay7</item>
  <item >Relay8</item>
  </string-array>
  </resources>

And in mu main.xml I am using a text view and toggle button

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
   android:layout_height="match_parent" >

   <TextView
     android:id="@+id/textView1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentLeft="true"
     android:layout_toLeftOf="@+id/toggleButton1"
     android:textSize="20dp" >
  </TextView>   


  <ToggleButton
     android:id="@+id/toggleButton1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
     android:layout_marginLeft="4dp"
     android:layout_marginRight="10dp"
      android:text="@string/On_Off" >

      </ToggleButton>


       </RelativeLayout>

when I click the toggle button it showing On and off.
But when I click on the list I am not getting any responses.

For my application I need to send some data while pressing the toggle button with respect to button condition.

  • 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-10T14:34:34+00:00Added an answer on June 10, 2026 at 2:34 pm
    ListView menuListView;  
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {        
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.menuitem);
        menuListView = (ListView) findViewById(R.id.menu);
        TextView cartItem = (TextView) findViewById(R.id.cartItem);
        Bundle b = getIntent().getExtras();
        int catId = b.getInt("categoryId");     
        List<MenuItem>  menuItems = getMenuItemsByCatId(catId); 
    
        MenuLazyAdapter menuLazyAdapter = new MenuLazyAdapter(this, menuItems);
        // Set the ListView adapter
    
        menuListView.setAdapter(menuLazyAdapter);
        menuListView.setOnItemClickListener(new OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id) {
                Toast.makeText(getApplicationContext(), "Clicked on :: "+ position, Toast.LENGTH_SHORT).show();
    
            }
        });
    
    
    }
    private List<MenuItem> getMenuItemsByCatId(int catId) {
        RomDbAdapter dbAdapter = new RomDbAdapter(MenuListView.this);
        dbAdapter.open();
    
        List<MenuItem> items = dbAdapter.getAllMenuByCatId(catId);
        dbAdapter.close();
    
        return items;
    }
    

    menuitem.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
    
    
        <LinearLayout 
             android:id="@+id/cart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"        
            android:layout_marginRight="5dip"       
            android:padding="3dip" >
            <TextView
            android:id="@+id/cartItem"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Menu drop here"
            android:gravity="right"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
        </LinearLayout>
        <ListView
            android:id="@+id/menu"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:cacheColorHint="#cccccc"
            android:scrollbars="vertical"
            android:smoothScrollbar="true" >
        </ListView>
    
    </LinearLayout>
    

    item.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dip" >
    
        <!-- ListRow Left sied Thumbnail image -->
    
        <LinearLayout
            android:id="@+id/thumbnail"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginRight="5dip"
            android:background="@drawable/image_bg"
            android:padding="3dip" >
    
            <ImageView
                android:id="@+id/item_image"
                android:layout_width="50dip"
                android:layout_height="50dip" />
        </LinearLayout>
    
        <!-- Title Of item -->
    
        <TextView
            android:id="@+id/itemName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/thumbnail"
            android:layout_toRightOf="@+id/thumbnail"
            android:text="Item Name"        
            android:textSize="15dip"
            android:textStyle="bold"
            android:typeface="sans" />
    
            <!-- Item  description -->
    
    
    
        <TextView
            android:id="@+id/ItemDesc"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/itemName"
            android:layout_toRightOf="@+id/thumbnail"
            android:text=" Fresh salad with lentils leafs"
            android:textSize="10dip" />
    
        <TextView
            android:id="@+id/itemPrice"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/ItemDesc"
            android:layout_below="@+id/ItemDesc"
            android:text="$10.00"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    
    </RelativeLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an application using WPF, and I need to make something that looks
I'm writing an application that manages todo lists. Unlike 'traditional' todo list applications I
I'm writing a WPF desktop application and have a view that needs to look
I'm writing some code to handle an application invitation request (FB.ui, method = apprequests),
I am writing an Outlook Add-in and want to do something (not relevant here)
I'm writing a simple blog-like application for Django and am trying to get the
I am writing a web application that has a page that returns a list
I am writing application where in my MainActivity I have list of items. When
I am writing application in Linux using C, pthreads and sockets. This will be
I am writing application on ActionScript for Android using Adobe AIR with native extentions.

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.