How to add text and toggle button above listView in android? -


i want add explanatory text , 1 toggle button on top of listview...i referred answers of many similar questions , tried code, mine text , toggle button gets added on top of every item of listview

my activity_first_point.xml contain listview follows:

<?xml version="1.0" encoding="utf-8"?> <linearlayout 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" android:orientation="vertical"    >          <listview     android:id="@+id/list"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:padding="20dp"     android:gravity="center"      android:background="@drawable/shape"     android:drawselectorontop="true"      >     </listview>    <textview     android:textisselectable="false"     android:paddingbottom="20dp"     android:textsize="40sp"     android:id="@+id/textitem"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:gravity="center"     android:textcolor="#ffffff"      />  </linearlayout>  

my java code follows:

public class menu extends listactivity{  string[] values={"owner","passcode","friends","settings","help"}; listview l; @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     listview l;     l=getlistview();     l.setbackgroundcolor(color.rgb(8,0,0));      setlistadapter(new arrayadapter<string>(menu.this,r.layout.activity_first_point,r.id.textitem,values)); 

you might adding view (the view having toggle button , textview) above list item, custom cell. instead of doing that, can add in header of listview like,

layoutinflater inflater = getlayoutinflater(); view header = inflater.inflate(r.layout.header, null); yourlistview.addheaderview(header, null, false); 

here, r.layout.headerview xml file contains textview , togglebutton. , can access by:

textview yourtext = (textview) header.findviewbyid(r.id.textview); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -