Packagemydefault.packge;ImportCOM.EXAMPLE.CODEVIEW.R;Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Color;ImportAndroid.graphics.Paint;ImportAndroid.graphics.Rect;ImportAndroid.os.Bundle;Importandroid.view.MotionEvent;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.view.ViewGroup.LayoutParams;ImportAndroid.view.View.OnTouchListener;ImportAndroid.widget.ArrayAdapter;ImportAndroid.widget.Button;Importandroid.widget.LinearLayout;ImportAndroid.widget.ListView;ImportAndroid.widget.TextView;ImportAndroid.widget.ToggleButton; Public classMainactivityextendsactivity{@Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub Super. OnCreate (savedinstancestate); //Layout ManagerLinearLayout layout =NewLinearLayout (mainactivity. This); ListView List=NewListView (mainactivity. This); List.setlayoutparams (NewLayoutparams (viewgroup.layoutparams.match_parent,viewgroup.layoutparams.match_parent)); //------------------------Arrayadapter<String> adapter =NewArrayadapter<string> (mainactivity. This, R.layout.text,Newstring[]{"White Guest", "Green Blue"}); List.setadapter (adapter); Layout.addview (list); This. Setcontentview (layout); } }
Xml:
<?xml version= "1.0" encoding= "Utf-8"? ><textview xmlns:android= "http://schemas.android.com/apk/res/ Android " android:id=" @+id/textview " android:layout_width=" Fill_parent " Android:layout_height= "Wrap_content"/>
Chapter II Example: Arrayadapter combined with ListView list view