• android:ListView实现 java程序员


    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;
    	}
    }
    

  • 相关阅读:
    javablogs
    Android学习笔记WIFI设备
    线程
    初次尝试Chrome扩展开发——以幻灯片方式显示网页内的图片
    could not find the main class, Program will exit(已解决)
    tomcat6.0配置(含配置视频下载)
    Windows下JDK1.6.0+Tomcat6.0的安装配置
    Java学习
    【翻译】在没有安装ASP.NET MVC3的服务器上运行ASP.NET MVC3的程序scottgu
    AForge.NET框架的使用
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215868.html
Copyright © 2020-2023  润新知