import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class MainActivity extends Activity {
ListView LV01;
Button BT01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//連結
LV01=(ListView) this.findViewById(R.id.LV01);
BT01=(Button) this.findViewById(R.id.BT01);
//定義事件
BT01.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO 自動產生的方法 Stub
ArrayList<String> alist=new ArrayList<String>();
alist.add("小白");
alist.add("小叮噹");
alist.add("小叮鈴");
alist.add("小新");
ArrayAdapter <String> Aadapter=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, alist);
LV01.setAdapter(Aadapter);
}
});
}
@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;
}
}
沒有留言:
張貼留言