-
代码1
步骤
查看全部 -
GridView课程目标
查看全部 -
GridView
查看全部 -
使用DatePicker以及TimePicker显示当前日期和时间注意事项
查看全部 -
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //获取日历的一个对象 cal = Calendar.getInstance(); //获取年月日时分秒的信息 year = cal.get(Calendar.YEAR); month = cal.get(Calendar.MONTH)+1; day = cal.get(Calendar.DAY_OF_MONTH); hour = cal.get(Calendar.HOUR_OF_DAY); minute = cal.get(Calendar.MINUTE); setTitle(Year+"-" + month + "-" + day + "-" + hour + "-" + minute); datePicker = (DatePicker) findViewById(R.id.datePicker); timePicker = (TimePicker) findViewById(R.id.timePicker); //datePicker初始化 datePicker.init(year, month, day, new onDateChangedListener() { }); }
查看全部 -
需求功能
查看全部 -
OnDateChangedListener和OnTimeChangedListener()
查看全部 -
总结 知识要点及注意事项
查看全部 -
public class MainActivity extends Activity implement OnItemClickListener, OnScrollListener { private ListView listView; private ArrayAdapter<String>arr_adapter; private SimpleAdapter simp_adapter; private List<Map<String, Object>>dataList; @Override protected void onCreate(Bundle saveInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView)findViewById(R.id.listView); //1、新建一个数据适配器 //ArrayAdapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源) //SimpleAdapter() /** * context: 上下文 * data: 数据源 (List<? extends Map<String, ?>> data) *一个Map所组成的List集合 * 每一个Map都会去对应ListView列表中的一行 *每一个Map(键-值对)中的键必须包含所有在from中所指定的键 * *resource: 列表项的布局文件ID *from: Map中的键名 *to: 绑定数据视图中的ID,与from成对应关系 */ //2、适配器加载数据源 String[] arr_data = {"imooc1", "imooc2" , "imooc3", "imooc4"}; dataList = new ArrayList<Map<String, Object>>(); arr_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item1, arr_data); //new SimpleAdapter(context, data, resource, from, to) simp_adapter = new SimpleAdapter(this, getData(), R.layout.item, new String[]{"pic", "text"}, new int[]{R.id.pic, R.id.text}); //3、视图(ListView)加载适配器 //listView.setAdapter(arr_adapter); listView.setAdapter(simp_adapter); //ListView加载事件监听器 listView.setOnItemClickListener(this); listView.setOnScrollListener(this); } private List<Map<String, Object>> getData() { for(int i=0; i<20; i++) { Map<String, Object>map = new HashMap<String, Object>(); map.put("pic", R.drawable.img1); map.put("text", "慕课网" + i); dataList.add(map); } return dataList; } public void onScrollStateChanged(AbsListView view, int ScorllState) { } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String text = listView.getItemAtPosition(position) + ""; Toast .makeText(this, "position=" + position + " text=" + text, Toast.LENGTH_SHORT).show(); } }
查看全部 -
public class MainActivity extends Activity implement OnItemClickListener, OnScrollListener { private ListView listView; private ArrayAdapter<String>arr_adapter; private SimpleAdapter simp_adapter; private List<Map<String, Object>>dataList; @Override protected void onCreate(Bundle saveInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView)findViewById(R.id.listView); //1、新建一个数据适配器 //ArrayAdapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源) //SimpleAdapter() /** * context: 上下文 * data: 数据源 (List<? extends Map<String, ?>> data) *一个Map所组成的List集合 * 每一个Map都会去对应ListView列表中的一行 *每一个Map(键-值对)中的键必须包含所有在from中所指定的键 * *resource: 列表项的布局文件ID *from: Map中的键名 *to: 绑定数据视图中的ID,与from成对应关系 */ //2、适配器加载数据源 String[] arr_data = {"imooc1", "imooc2" , "imooc3", "imooc4"}; dataList = new ArrayList<Map<String, Object>>(); arr_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item1, arr_data); //new SimpleAdapter(context, data, resource, from, to) simp_adapter = new SimpleAdapter(this, getData(), R.layout.item, new String[]{"pic", "text"}, new int[]{R.id.pic, R.id.text}); //3、视图(ListView)加载适配器 //listView.setAdapter(arr_adapter); listView.setAdapter(simp_adapter); //ListView加载事件监听器 listView.setOnItemClickListener(this); listView.setOnScrollListener(this); } private List<Map<String, Object>> getData() { for(int i=0; i<20; i++) { Map<String, Object>map = new HashMap<String, Object>(); map.put("pic", R.drawable.img1); map.put("text", "慕课网" + i); dataList.add(map); } return dataList; } public void onScrollStateChanged(AbsListView view, int ScorllState) { switch(scrollState) { case SCROLL_STATE_FLING: log.i("Main", "手指离开屏幕,由于用力滑了一下,视图扔继续滚动"); Map<String, Object>map = new HashMap<String, Object>(); map.put("pic', R.drawable.img1); map.put("text", "增加项"); dataList.add(map); //重新刷新列表界面 simp_adapter.notifyDataSetChange(); break; case SCROLL_STATE_IDLE: log.i("Main", "视图已经停止滑动"); break; case SCROLL_STATE_TOUCH_SCROLL: log.i("Main", "手指没有离开屏幕,视图正在滑动"); break; } } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String text = listView.getItemAtPosition(position) + ""; Toast .makeText(this, "position=" + position + " text=" + text, Toast.LENGTH_SHORT).show(); } }
item.xml
<LinearLayout android: layout_width = "match_parent" android: layout_height = "match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android: orientation = "horizontal" > <ImageView android: id = "@+id/pic" android: layout_marginLeft = "15dp" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: src = "@drawable/img1" /> <TextView android: id = "@+id/text" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: textSize = "20sp" android: textColor = "#000" android: text = "demo" /> <LinearLayout/>
查看全部 -
监听器
查看全部 -
MainActivity.java
public class MainActivity extends Activity { private ListView listView; private ArrayAdapter<String>arr_adapter; private SimpleAdapter simp_adapter; private List<Map<String, Object>>dataList; @Override protected void onCreate(Bundle saveInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView)findViewById(R.id.listView); //1、新建一个数据适配器 //ArrayAdapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源) //SimpleAdapter() /** * context: 上下文 * data: 数据源 (List<? extends Map<String, ?>> data) *一个Map所组成的List集合 * 每一个Map都会去对应ListView列表中的一行 *每一个Map(键-值对)中的键必须包含所有在from中所指定的键 * *resource: 列表项的布局文件ID *from: Map中的键名 *to: 绑定数据视图中的ID,与from成对应关系 */ //2、适配器加载数据源 String[] arr_data = {"imooc1", "imooc2" , "imooc3", "imooc4"}; dataList = new ArrayList<Map<String, Object>>(); arr_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item1, arr_data); //new SimpleAdapter(context, data, resource, from, to) simp_adapter = new SimpleAdapter(this, getData(), R.layout.item, new String[]{"pic", "text"}, new int[]{R.id.pic, R.id.text}); //3、视图(ListView)加载适配器 //listView.setAdapter(arr_adapter); listView.setAdapter(simp_adapter); } private List<Map<String, Object>> getData() { for(int i=0; i<20; i++) { Map<String, Object>map = new HashMap<String, Object>(); map.put("pic", R.drawable.img1); map.put("text", "慕课网" + i); dataList.add(map); } return dataList; } }
item.xml
<LinearLayout android: layout_width = "match_parent" android: layout_height = "match_parent" xmlns:android="http://schemas.android.com/apk/res/android" android: orientation = "horizontal" > <ImageView android: id = "@+id/pic" android: layout_marginLeft = "15dp" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: src = "@drawable/img1" /> <TextView android: id = "@+id/text" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: textSize = "20sp" android: textColor = "#000" android: text = "demo" /> <LinearLayout/>
查看全部 -
public class MainActivity extends Activity { private ListView listView; private ArrayAdapter<String>arr_adapter; private SimpleAdapter simp_adapter; @Override protected void onCreate(Bundle saveInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView)findViewById(R.id.listView); //1、新建一个数据适配器 //ArrayAdapter(上下文,当前ListView加载的每一个列表项所对应的布局文件,数据源) //2、适配器加载数据源 String[] arr_data = {"imooc1", "imooc2" , "imooc3", "imooc4"}; arr_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item1, arr_data); //3、视图(ListView)加载适配器 listView.setAdapter(arr_adapter); } }
查看全部 -
数据适配器
查看全部 -
ListView
查看全部
举报
0/150
提交
取消