package com.zhouzijing.android;
import java.util.ArrayList;
import java.util.List;
import com.zhouzijing.android.util.MenuEntity;
import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class ListViewDemo extends Activity {
//定义Person
List persons ;
ListAdapter adapter = null;
ListView listView01 = null;
EditText editTextPersonName = null;
//定义上下文菜单
final private static int CONTEXT_MENU_EDIT = 0;//菜单[编辑]的编号
final private static int CONTEXT_MENU_SHARE = 1;//菜单[分享]的编号
final private static int CONTEXT_MENU_DELETE = 2;//菜单[删除]的编号
final private static int CONTEXT_MENU_CANCEL = 3;//菜单[取消]的编号
private MenuEntity[] contextMenus = {
new MenuEntity(0, CONTEXT_MENU_EDIT, 0, "编辑"),
new MenuEntity(0, CONTEXT_MENU_SHARE, 1, "分享"),
new MenuEntity(0, CONTEXT_MENU_DELETE, 2, "删除"),
new MenuEntity(0, CONTEXT_MENU_CANCEL, 3, "取消"),
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view01);
//获取组件
listView01 = (ListView)findViewById(R.id.listView01);
editTextPersonName = (EditText)findViewById(R.id.editText01Edit);
//显示ListView
initListAllPersons();
showByMyBaseAdapter();
//初始化ListView的事件
//initListView01Event();
}
public void initListAllPersons(){
persons = new ArrayList();
persons.add(new Person(100,"李小龙","香港",android.R.drawable.ic_delete));
persons.add(new Person(101,"施瓦辛格","美国",android.R.drawable.ic_dialog_alert));
persons.add(new Person(102,"戴安娜王妃","英国",android.R.drawable.ic_dialog_dialer));
persons.add(new Person(103,"成龙","香港",android.R.drawable.ic_dialog_map));
persons.add(new Person(104,"史泰龙","美国",android.R.drawable.ic_lock_idle_alarm));
persons.add(new Person(105,"圣女贞德","法国",android.R.drawable.ic_media_next));
persons.add(new Person(106,"列宁","苏联",android.R.drawable.ic_media_play));
persons.add(new Person(107,"爱迪生","美国",android.R.drawable.ic_menu_add));
persons.add(new Person(108,"孔子","中国",android.R.drawable.ic_media_rew));
persons.add(new Person(109,"杨七郎","宋朝",android.R.drawable.ic_menu_zoom));
persons.add(new Person(110,"秦始皇","秦国",android.R.drawable.ic_menu_agenda));
persons.add(new Person(111,"岳飞","宋朝",android.R.drawable.ic_lock_lock));
}
public void showByMyBaseAdapter(){
adapter = new MyBaseAdapter(this, persons);
listView01.setAdapter(adapter);
}
/**
* 按钮button01Edit的onClick事件.
* @param view
*/
public void editPersonAndRefreshListView01(View view){
//获取TextEdit数据
String value = editTextPersonName.getText().toString();
//更新ListView的内容,并且动态刷新.
persons.get(0).name=value;
((BaseAdapter) adapter).notifyDataSetChanged();
}
/**
* 初始化listView01的事件.
*/
public void initListView01Event(){
//ListView的item点击事件
listView01.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
"[OnItemClickListener]点击了:"+persons.get(position).name,
Toast.LENGTH_SHORT).show();
}
});
//ListView的item长按点击事件
listView01.setOnItemLongClickListener(new OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
"[OnItemLongClickListener]点击了:"+persons.get(position).name,
Toast.LENGTH_SHORT).show();
return false;
}
});
//ListView的键盘选中事件(直接触摸屏幕选中不会激发)
listView01.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
"[OnItemSelectedListener:onItemSelected]点击了:"
+persons.get(position).name,
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView> parent) {
Toast.makeText(getApplicationContext(),
"[OnItemSelectedListener:onNothingSelected]点击了",
Toast.LENGTH_SHORT).show();
}
});
//ListView组件:创建上下文菜单
listView01.setOnCreateContextMenuListener(new OnCreateContextMenuListener(){
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
//获取上下文菜单点击的ListView的位置(position)属性
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int position = info.position;
//设置上下文菜单标题
menu.setHeaderTitle(persons.get(position).name);
//设置上下文菜单栏目
MenuEntity menuEntity = null;
for(int i=0;i
Person类代码
Java代码
package com.zhouzijing.android;
publicclass Person {
publicint id;
public String name;
public String address;
publicint photo;
public Person(int id, String name, String address,int photo) {
super();
this.id = id;
this.name = name;
this.address = address;
this.photo = photo;
}
}
package com.zhouzijing.android;
public class Person {
public int id;
public String name;
public String address;
public int photo;
public Person(int id, String name, String address,int photo) {
super();
this.id = id;
this.name = name;
this.address = address;
this.photo = photo;
}
}
自定义的BaseAdapter类代码
Java代码
package com.zhouzijing.android;
import java.util.List;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
publicclass MyBaseAdapter extends BaseAdapter {
private List persons;
Context context;
public MyBaseAdapter(Context context,List persons){
this.persons = persons;
this.context = context;
}
@Override
publicint getCount() {
return (persons==null)?0:persons.size();
}
@Override
public Object getItem(int position) {
return persons.get(position);
}
@Override
publiclong getItemId(int position) {
return position;
}
publicclass ViewHolder{
TextView textViewItem01;
TextView textViewItem02;
TextView textViewItem03;
ImageView imageView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
今天和同事争论一问题,关于静态变量与非静态变量的初始化顺序,谁先谁后,最终想整理出来!测试代码:
import java.util.Map;
public class T {
public static T t = new T();
private Map map = new HashMap();
public T(){
System.out.println(&quo
完整命令
CREATE DATABASE mynewdb USER SYS IDENTIFIED BY sys_password USER SYSTEM IDENTIFIED BY system_password LOGFILE GROUP 1 ('/u01/logs/my/redo01a.log','/u02/logs/m
多线程并发使用同一个channel
java.nio.BufferOverflowException: null
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:183) ~[na:1.7.0_60-ea]
at java.nio.ByteBuffer.put(ByteBuffer.java:832) ~[na:1.7.0_60-ea]