当前位置: 编程技术>移动开发
本页文章导读:
▪在UINavigationController的导航栏中增添UISegmentedControl 在UINavigationController的导航栏中添加UISegmentedControl
UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithFrame:CGRectMake(80.0f, 8.0f, 200.0f, 30.0f) ]; [segmentedControl insertSegmentWithTitle:@"Food to eat.........
▪ 替ListView创建ContextMenu 为ListView创建ContextMenu
ContextMenu称为上下文菜单,一般在控件上长按时弹出。今天我们学习ContextMenu的用法,这里与listview相结合,先在ListView显示几个Item,然后在Item上长按,弹出一个菜单(.........
▪ 随机取两个数目字时间的任意一个数字 随机取两个数字时间的任意一个数字
随机取两个数字之间的任意一个数字,代码如下:public class Test { public static void main(String[] args) { long max = 1321672754175l; long min = 1321672694175l; Random r.........
[1]在UINavigationController的导航栏中增添UISegmentedControl
来源: 互联网 发布时间: 2014-02-18
在UINavigationController的导航栏中添加UISegmentedControl
UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithFrame:CGRectMake(80.0f, 8.0f, 200.0f, 30.0f) ];
[segmentedControl insertSegmentWithTitle:@"Food to eat" atIndex:0 animated:YES];
[segmentedControl insertSegmentWithTitle:@"Food to avoid" atIndex:1 animated:YES];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
segmentedControl.multipleTouchEnabled=NO;
[segmentedControl addTarget:self action:@selector(Selectbutton:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segButton;
[segButton release];
UISegmentedControl *segmentedControl=[[UISegmentedControl alloc] initWithFrame:CGRectMake(80.0f, 8.0f, 200.0f, 30.0f) ];
[segmentedControl insertSegmentWithTitle:@"Food to eat" atIndex:0 animated:YES];
[segmentedControl insertSegmentWithTitle:@"Food to avoid" atIndex:1 animated:YES];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
segmentedControl.multipleTouchEnabled=NO;
[segmentedControl addTarget:self action:@selector(Selectbutton:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *segButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segButton;
[segButton release];
[2] 替ListView创建ContextMenu
来源: 互联网 发布时间: 2014-02-18
为ListView创建ContextMenu
ContextMenu称为上下文菜单,一般在控件上长按时弹出。今天我们学习ContextMenu的用法,这里与listview相结合,先在ListView显示几个Item,然后在Item上长按,弹出一个菜单(就是ContextMenu),点击菜单上的项目,提示刚才长按的Item的Position。
main.xml文件
菜单有3个条目,在/res/menu/test_menu.xml中定义,和OptionMenu差不多,只是没有Icon
ContextMenu称为上下文菜单,一般在控件上长按时弹出。今天我们学习ContextMenu的用法,这里与listview相结合,先在ListView显示几个Item,然后在Item上长按,弹出一个菜单(就是ContextMenu),点击菜单上的项目,提示刚才长按的Item的Position。
main.xml文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/text" android:text="zzz" android:textSize="18sp" android:textColor="#FFFFFF" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"> </ListView> </LinearLayout>
菜单有3个条目,在/res/menu/test_menu.xml中定义,和OptionMenu差不多,只是没有Icon
package com.hello.menu; import android.app.Activity; import android.os.Bundle; import android.view.ContextMenu; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ContextMenu.ContextMenuInfo; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.TextView; public class ApiDemos extends Activity { /** Called when the activity is first created. */ private TextView mTextView; private ListView mListView; private String [] values; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mTextView = (TextView) findViewById(R.id.text); //下面的代码用于初始化一些数据 values = new String[30]; StringBuilder sb = new StringBuilder("z"); for (int i = 0; i < values.length; i++) { sb.append(i); values[i] = sb.toString(); } mListView = (ListView) findViewById(R.id.list); mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values)); mTextView.setText(String.valueOf(mListView.getAdapter().getCount())); //为ListView注册ContextMenu registerForContextMenu(mListView); } //创建ContextMenu @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { // TODO Auto-generated method stub if (v.getId() == R.id.list) { MenuInflater inflater = getMenuInflater(); menu.setHeaderTitle("contextView sample").setHeaderIcon(R.drawable.icon); inflater.inflate(R.menu.test_menu, menu); } super.onCreateContextMenu(menu, v, menuInfo); } @Override public boolean onContextItemSelected(MenuItem item) { // TODO Auto-generated method stub if (item.getMenuInfo() instanceof AdapterContextMenuInfo) { AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo(); //处理菜单的点击事件 switch (item.getItemId()) { case R.id.call: mTextView.setText(item.getTitle().toString() + menuInfo.position); break; case R.id.cc: mTextView.setText(item.getTitle().toString() + menuInfo.position); break; case R.id.poweroff : mTextView.setText(item.getTitle().toString() + menuInfo.position); break; } } return super.onContextItemSelected(item); } }
[3] 随机取两个数目字时间的任意一个数字
来源: 互联网 发布时间: 2014-02-18
随机取两个数字时间的任意一个数字
随机取两个数字之间的任意一个数字,代码如下:
public class Test {
public static void main(String[] args) {
long max = 1321672754175l;
long min = 1321672694175l;
Random random = new Random();
long s = Math.round(Math.random()*(max-min)+min);
System.out.println(s);
}
}
随机取两个数字之间的任意一个数字,代码如下:
public class Test {
public static void main(String[] args) {
long max = 1321672754175l;
long min = 1321672694175l;
Random random = new Random();
long s = Math.round(Math.random()*(max-min)+min);
System.out.println(s);
}
}
最新技术文章: