zoukankan      html  css  js  c++  java
  • 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;
    	}
    }
    

  • 相关阅读:
    python appium环境搭建
    github 删除某个文件
    python 导入的模块使用了相对路径,导致找不到文件错误
    python asyncio协程
    python 获取调用函数的名字和行号
    monkey测试命令
    python 属性查询顺序,数据描述符
    JS各循环的差别
    AngularJS复习小结
    那些不正经的前端笔试题
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215868.html
Copyright © 2011-2022 走看看