package com.example.list; import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android.view.Menu; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; public class MainActivity extends Activity { private static final String array[]={ "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday","Sunday" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); LinearLayout MyLayout=new LinearLayout(this); MyLayout.setOrientation(LinearLayout.VERTICAL); MyLayout.setBackgroundColor(Color.BLACK); TextView mtv=new TextView(this); mtv.setText("This is a ListView Test"); LinearLayout.LayoutParams Param1=new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); MyLayout.addView(mtv,Param1); ListView MyListView=new ListView(this); MyListView.setBackgroundColor(Color.GRAY); LinearLayout.LayoutParams Param2=new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); MyLayout.addView(MyListView,Param2); setContentView(MyLayout); ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.simple_list_item,array); MyListView.setAdapter(adapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }