android - How create a View, that contains Buttons and a List within the same Activity? -


what syntax (xml , java) should use create view, have couple of buttons ("next" , "back") @ top of screen, , list, located below buttons? have tried following, did not work @ all:

main.xml:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     > <textview       android:layout_width="fill_parent"      android:layout_height="wrap_content"      android:text="@string/hello"     /> <button android:text="@+id/button01" android:id="@+id/button01"  android:layout_width="wrap_content" android:layout_height="wrap_content"> </button> <listview android:id="@+id/listview01" android:layout_width="fill_parent"  android:layout_height="fill_parent"> </listview> </linearlayout> 

firstscreen.java:

public class firstscreen extends listactivity {     /** called when activity first created. */     string [] entries = {"one","two","three"};     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          arrayadapter<string> adapter =        new arrayadapter<string>(this,android.r.layout.simple_list_item_1,entries);         listview lv = new listview(this,null,r.id.listview01);         setlistadapter(adapter);     } } 

here xml layout should work :

<?xml version="1.0" encoding="utf-8"?> <linearlayout     android:layout_width="fill_parent"     android:layout_height="fill_parent"      android:orientation="vertical"     xmlns:android="http://schemas.android.com/apk/res/android">     <textview           android:layout_width="fill_parent"          android:layout_height="wrap_content"          android:text="hello"     />     <linearlayout         android:layout_width="fill_parent"         android:layout_height="wrap_content">         <button             android:id="@+id/next"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:text="next"             android:layout_weight="1"             android:textsize="16dip"/>         <button              android:id="@+id/back"             android:layout_width="fill_parent"             android:layout_height="fill_parent"             android:layout_weight="1"             android:text="back"/>            </linearlayout>     <listview          android:id="@+id/your_list"          android:layout_width="fill_parent"         android:layout_height="fill_parent">     </listview> </linearlayout> 

and java code.

... string[] entries = { "one", "two", "three" }; arrayadapter<string> adapter = new arrayadapter<string>(this,         android.r.layout.simple_list_item_1, entries); listview lv = (listview) findviewbyid(r.id.your_list); lv.setadapter(adapter); ... 

i hope answer question.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -