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

  • 相关阅读:
    两次动态输入和while的结合使用
    索引切片步长
    12.⽤户登陆(三次输错机会)且每次输错误时显示剩余错误次数(提示:使⽤字符串格式化)
    输出1-100的所以奇数或偶数
    求1-2+3-4+5 ... 99的所有数的和
    求1-100所有数的和
    三次登录机会
    while输入12345689
    while和格式化输出的复合使用
    44
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215868.html
Copyright © 2020-2023  润新知