ListView2

MyDemo.java

package com.jackie.listviewproject;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;


public class MainActivity extends Activity {
  
private String data[]={"魔樂科技1","魔樂科技2","魔樂科技3",
"魔樂科技4","魔樂科技5","魔樂科技6","魔樂科技7",
"魔樂科技8","魔樂科技9","魔樂科技10","魔樂科技11",
"魔樂科技12","魔樂科技13","魔樂科技14","魔樂科技15"};
private ListView listView=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        this.listView=new ListView(this);
        this.listView.setAdapter(new ArrayAdapter<String>(this,
        android.R.layout.simple_expandable_list_item_1,
        this.data));
  super.setContentView(this.listView);
}


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

}
Main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />


</RelativeLayout>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章