标签:roi ali note parent .net data return 视频 layout
manifest
A跳转B,在B的文件中用permission权限,然后A就无权跳转到B,如果在A中用uses-permission把权限给了A,那么A就可以跳转到B了.可以通俗的说,permission给B了一把锁,A要进门,就要用uses-permission得到一把钥匙.
onitemclicklister+onscrolllistner
1 public class FActivity extends Activity implements OnItemClickListener,OnScrollListener{ 2 private ListView lv; 3 private SimpleAdapter sim_adapter; 4 private List<Map<String, Object>> datalist; 5 @Override 6 protected void onCreate(Bundle savedInstanceState) { 7 // TODO Auto-generated method stub 8 super.onCreate(savedInstanceState); 9 setContentView(R.layout.factivity); 10 11 lv=(ListView) findViewById(R.id.listView1); 12 sim_adapter =new SimpleAdapter(this, getdata(), R.layout.item, new String[]{"pic","text"}, new int[]{R.id.imageView1,R.id.textView1}); 13 14 lv.setAdapter(sim_adapter); 15 lv.setOnItemClickListener(this); 16 lv.setOnScrollListener(this); 17 18 } 19 private List<Map<String, Object>> getdata(){ 20 datalist =new ArrayList<Map<String,Object>>(); 21 for (int i=0;i<10;i++) 22 { 23 Map<String, Object> map = new HashMap<String, Object>(); 24 map.put("pic", R.drawable.ic_launcher); 25 map.put("text", "慕课网"+i); 26 datalist.add(map); 27 } 28 return datalist; 29 } 30 @Override 31 public void onScrollStateChanged(AbsListView view, int scrollState) { 32 switch (scrollState) { 33 case SCROLL_STATE_FLING: 34 Map<String, Object> map =new HashMap<String, Object>(); 35 map.put("pic", R.drawable.ic_launcher); 36 map.put("text", "增加item"); 37 datalist.add(map); 38 sim_adapter.notifyDataSetChanged(); 39 break; 40 case SCROLL_STATE_IDLE: 41 42 break; 43 case SCROLL_STATE_TOUCH_SCROLL: 44 45 break; 46 47 default: 48 break; 49 } 50 51 } 52 @Override 53 public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 54 // TODO 自动生成的方法存根 55 56 } 57 58 @Override 59 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 60 String text=lv.getItemAtPosition(position)+""; 61 Toast.makeText(this, "位置:"+position+"text="+text, Toast.LENGTH_SHORT) 62 .show(); 63 64 } 65 }
**Picker:选择器
DatePicker日历选择器
Timepicker时间选择器**
1 public class FActivity extends Activity { 2 private TimePicker tp; 3 private DatePicker dp; 4 private Calendar cal; 5 int year; 6 int month; 7 int day; 8 int hour; 9 int minute; 10 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 // TODO Auto-generated method stub 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.factivity); 16 17 cal=Calendar.getInstance();//生成日历类的对象实例 18 year=cal.get(Calendar.YEAR); 19 month=cal.get(Calendar.MONTH)+1;//注意唯一例外是month需要+1 20 day=cal.get(Calendar.DAY_OF_MONTH); 21 hour=cal.get(Calendar.HOUR_OF_DAY); 22 minute=cal.get(Calendar.MINUTE); 23 setTitle(year+"-"+month+"-"+day+" "+hour+":"+minute); 24 25 tp=(TimePicker) findViewById(R.id.timePicker1); 26 dp=(DatePicker) findViewById(R.id.datePicker1); 27 dp.init(year, Calendar.MONTH, day, new OnDateChangedListener() { 28 29 @Override 30 public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 31 setTitle(year+"-"+(monthOfYear+1)+"-"+dayOfMonth+" "+hour+":"+minute); 32 33 34 } 35 }); 36 tp.setOnTimeChangedListener(new OnTimeChangedListener() { 37 38 @Override 39 public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { 40 41 setTitle(year+"-"+month+"-"+day+" "+hourOfDay+":"+minute); 42 } 43 }); 44 } 45 46 47 }
注意month的加减一问题。
datepicker需要用init()方法,在方法中调用监听器,而时间选择器直接调用监听器。
dialog形式
匿名内部类实现。
1 //参数callback是监听器 2 new DatePickerDialog(this, new OnDateSetListener() { 3 4 @Override 5 public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 6 setTitle(year+"-"+(monthOfYear+1)+"-"+dayOfMonth+" "+hour+":"+minute); 7 8 } 9 }, year, cal.get(Calendar.MONTH), day).show(); 10 11 new TimePickerDialog(this, new OnTimeSetListener() { 12 13 @Override 14 public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 15 setTitle(year+"-"+month+"-"+day+" "+hourOfDay+":"+minute); 16 17 } 18 }, hour, minute, true); 19 }
gridview
1 public class FActivity extends Activity implements OnItemClickListener{ 2 private GridView gv; 3 private SimpleAdapter sim_adapter; 4 private List<Map<String, Object>> datalist; 5 int[] iconid={R.drawable.calculate,R.drawable.calendar,R.drawable.clock, 6 R.drawable.contact,R.drawable.message,R.drawable.money,R.drawable.notebook, 7 R.drawable.rest,R.drawable.setting,R.drawable.studyhat,R.drawable.trashbox, 8 R.drawable.weightscale}; 9 String[] iconname={"calculate","calendar","clock","contact","message","money", 10 "notebook","rest","setting","studyhat","trashbox","weightscale"}; 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 // TODO Auto-generated method stub 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.factivity); 16 17 18 datalist=new ArrayList<Map<String,Object>>(); 19 20 gv=(GridView) findViewById(R.id.gridView1); 21 sim_adapter=new SimpleAdapter(this, getdata(), R.layout.item, new String[]{"pic","text"}, new int[]{R.id.imageView1,R.id.textView1}); 22 gv.setAdapter(sim_adapter); 23 24 gv.setOnItemClickListener(this); 25 } 26 27 private List<Map<String, Object>> getdata() { 28 29 for (int i=0;i<iconid.length;i++){ 30 Map<String, Object> map=new HashMap<String, Object>(); 31 map.put("pic", iconid[i]); 32 map.put("text", iconname[i]); 33 datalist.add(map); 34 } 35 36 37 return datalist; 38 39 40 } 41 42 @Override 43 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 44 Toast.makeText(this, "我是"+iconname[position], Toast.LENGTH_SHORT).show(); 45 46 } 47 48 49 50 51 }
spinner
1 public class FActivity extends Activity implements OnItemSelectedListener{ 2 private TextView txt; 3 private Spinner spin; 4 private List<String> list; 5 private ArrayAdapter<String> arr_adapter; 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 // TODO Auto-generated method stub 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.factivity); 11 12 txt=(TextView) findViewById(R.id.textView1); 13 spin=(Spinner) findViewById(R.id.spinner1); 14 list=new ArrayList<String>(); 15 list.add("北京"); 16 list.add("上海"); 17 list.add("广州"); 18 list.add("深圳"); 19 arr_adapter=new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list); 20 arr_adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line); 21 spin.setAdapter(arr_adapter); 22 spin.setOnItemSelectedListener(this); 23 24 } 25 26 @Override 27 public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { 28 String cityname=arr_adapter.getItem(position); 29 // String name =list.get(position); 30 txt.setText("我选择居住在:"+cityname); 31 32 } 33 @Override 34 public void onNothingSelected(AdapterView<?> parent) { 35 // TODO 自动生成的方法存根 36 37 } 38 39 }
标签:roi ali note parent .net data return 视频 layout
原文地址:https://www.cnblogs.com/twomeng/p/9476292.html