Archive for August, 2012
Toggle Button inside ListView in android
Posted by Deepthi Girija Thampi in Snippets on August 29, 2012
The XML File:
<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" > <ToggleButton android:id="@+id/toggleButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/On_Off" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/toggleButton1" android:layout_marginLeft="20dp" />
</RelativeLayout>
Now The Code:
package com.deepthi.mylistviewwithtogglebutton; import android.os.Bundle; import android.app.ListActivity; import android.view.Menu; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; public class MyListViewWithToggle extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(),R.layout.activity_my_list_view_with_toggle,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(); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_my_list_view_with_toggle, menu); return true; } }
The String.xml is given below:
<resources> <string name="app_name">MyListViewWithToggleButton</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="title_activity_my_list_view_with_toggle">MyListViewWithToggle</string> <string name="On_Off">ON/OFF</string> <string-array name="Strings"> <item >Android Desk</item> <item >Android Desk by Deepthi.G</item> <item >ListView in android</item> <item >Android Tutorials</item> </string-array> </resources>
Android, Android Desk, androiddesk, code snippet, ListView in Android, Snippets, Toggle Button in android, Toggle Button inside Listview
-
You are currently browsing the archives for August, 2012
About Me
I'm a beginner in Android and interested in exploring more into the Android World.I love sharing my knowledge because it increases as we do.Come, lets share and thus expand our knowledge space in Android.
Blog Stats
- 381,234 Pageviews
Recent Posts
- Toggle Button inside ListView in android
- Creating Dynamic Views in android
- Blocking a call without user intervention in android with an example
- A Simple ListView in Android
- Bluetooth in Android-Part II
- Bluetooth in Android-Part I
- Started Service in Android
- Service in Android
- Spinner in Android
- AutoCompleteTextView in Android
- Toggle Button in android
- XML layout in android
- How to implement a Button Click event in Android without onClickListener?
- Button in android
- How to change the usual icon of your application in Android?
- Activity in android
- Creating a Progress Dialog in Android:
- Custom Dialog in Android
- Custom Toast Notification in Android with an Example
- Toast Notification in Android with a simple example
- Check the usage of CheckBox in an Android activity
- Dialog in Android
- Just an Introduction to Notifications
- Implicit Intent
- Explicit Intent
- Status Bar Notification with an Example
- Horizontal and Vertical Scrolling in Android
- Fundamental Building Blocks of an Android Application
- Introducing ANDROID:
Archives
- August 2012 (3)
- June 2012 (1)
- May 2012 (2)
- April 2012 (2)
- March 2012 (3)
- February 2012 (5)
- January 2012 (8)
- December 2011 (5)
Top Posts & Pages
Android
action Activity in android Alert Dialog in android Alert dialog with list of items Alert Dialog with one button Alert Dialog with two buttons Android android architechture Android Bluetooth Android Desk androiddesk Android Framework Android Runtime Android Tutorial Application components Applications architechture Bluetooth Bluetooth in Android Bound Service in Android Broadcast Receivers Broadcast Receivers in android Building Blocks Button in android Communication between essential components in android components of Android OS Content Providers Contents providers in android Dalvik Virtual Machine data and category dialog Dialog in android DVM essential building blocks Explicit Intent Explicit Intent with an Example Fundamental Building Blocks Horizontal and Vertical Scrolling in android HorizontalScrollView How to move from one activity to another using an intent How to perform Horizontal and Vertical scrolling Implicit Intent implicit intent using an example Intent Intent Filters intents Introducing android Introduction to Notifications Libraries Linux Kernel ListView in Android Mai makeText() making a call using implicit intent Multiple Notifications Notification Notification in android Notification Manager notifications Positioning the Toast Scrolling in android ScrollView sending sms using implicit intent Service in android Services in android setGravity() Started Service in Android Status Bar Notification Status Bar Notification with an example toast Toast Notification Toast Notification with an example Toggle Button in android Use of ScrollViews viewing contacts using implicit intent- Join 114 other subscribers