因为日历是系统自带的,所以读写它一定要申请权限,也就是在AndroidManifestxml加如下两行代码(一个读一个写):
<uses-permission android:name="androidpermissionREAD_CALENDAR"/>
<uses-permission android:name="androidpermissionWRITE_CALENDAR"/>
Android中日历用了三个URL,分别是日历用户的URL,事件的URL,事件提醒URL,三个URL在Android21之前是如下的样子:
calanderURL = "content://calendar/calendars";
calanderEventURL = "content://calendar/events";
calanderRemiderURL= "content://calendar/reminders";
但是在Android22版本以后,三个URL有了改变,变成如下的样子:
calanderURL = "content://comandroidcalendar/calendars";
calanderEventURL = "content://comandroidcalendar/events";
calanderRemiderURL = "content://comandroidcalendar/reminders";
简单的Demo,按照我的步骤一步一步的来:
第一步:新建一个Android工程命名为CalendarDemo
第二步:修改mainxml布局文件,增加了三个按钮,代码如下:
<xml version="10" encoding="utf-8">
<LinearLayout xmlns:android=">
lz 你好
具体代码如下:
import javaawt;import javamath;
import javaxswing;
import javaawtevent;
public class Test extends JFrame{
private JPanel panel;
private JLabel one,equ,result,img,end;
private JTextField input;
private JButton check;
private int first, second;
public Test(){
super("小程序查看器");
one = new JLabel("小程序");
onesetFont(new Font("宋体", FontPLAIN, 15));
makeRandom();
equ = new JLabel(first + "+" + second + "=");
input = new JTextField(10);
check = new JButton("检查");
checkaddActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int r = IntegerparseInt(inputgetText());
if(first+second == r){
resultsetText("you are right!");
}
else{
resultsetText("you are wrong!");
}
}
});
result = new JLabel();
img = new JLabel(new ImageIcon("1jpg"));
panel = new JPanel(new FlowLayout(FlowLayoutCENTER, 5, 5));
paneladd(equ);
paneladd(input);
paneladd(check);
paneladd(result);
paneladd(img);
end = new JLabel("小程序已启动。");
endsetFont(new Font("宋体", FontPLAIN, 15));
endsetOpaque(true);
endsetBackground(ColorWHITE);
getContentPane()add(one, BorderLayoutNORTH);
getContentPane()add(panel, BorderLayoutCENTER);
getContentPane()add(end, BorderLayoutSOUTH);
setSize(230, 230);
setLocationRelativeTo(null);
setDefaultCloseOperation(3);
setVisible(true);
}
public void makeRandom(){
first = (int)(Mathrandom() 100 + 1);
second = (int)(Mathrandom() 100 + 1);
}
public static void main (String[] args) {
new Test();
}
}
运行结果:
希望能帮助你哈
下面是HTML代码:
<html>
<script language="javascript">
function on_submit()
{//验证数据的合法性
if (form1usernamevalue == "")
{
alert("用户名不能为空,请输入用户名!");
form1usernamefocus();
return false;
}
if (form1userpasswordvalue == "")
{
alert("用户密码不能为空,请输入密码!");
form1userpasswordfocus();
return false;
}
if (form1reuserpasswordvalue == "")
{
alert("用户确认密码不能为空,请输入密码!");
form1reuserpasswordfocus();
return false;
}
if (form1userpasswordvalue != form1reuserpasswordvalue)
{
alert("密码与确认密码不同!");
form1userpasswordfocus();
return false;
}
if (!(form1idnumbervaluelength == 15) && !(form1idnumbervaluelength == 18))
{
alert("身份z输入有误,请重新输入!");
form1idnumberfocus();
return false;
}
if (form1emavaluelength == 0)
{
alert("请输入E-mail地址!");
form1emafocus();
return false;
}
if (form1emavaluelength != 0)
{
for (i=0; i<form1emavaluelength; i++)
if (form1emavaluecharAt(i)=="@")
break;
if (i == form1emavaluelength)
{
alert("非法E-Mail地址!");
form1emafocus();
return false;
}
}
else
{
alert("请输入E-mail!");
form1emafocus();
return false;
}
}
</script>
<head>
<meta >
<title>新用户注册</title>
</head>
<body>
<form method="POST" action="registjsp" name="form1"
onsubmit="return on_submit()">
新用户注册
<br>
<br>
用户名():
<input type="text" name="username" size=20>
<br>
密 码():
<input type="password" name="userpassword" size="20">
<br>
再输一次密码():
<input type="password" name="reuserpassword" size="20">
<br>
性 别:
<input type="radio" value="男" checked name="sex">
男
<input type="radio" name="sex" value="女">
女
<br>
出生年月:
<input name="year" size="4" maxlength="4">
年
<select name="month">
<option value="1" selected>
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
<option value="6">
6
</option>
<option value="7">
7
</option>
<option value="8">
8
</option>
<option value="9">
9
</option>
<option value="10">
10
</option>
<option value="11">
11
</option>
<option value="12">
12
</option>
</select>
月
<input name="day" size="3" maxlength=4>
日
<br>
身份z号:
<input type="text" name="idnumber" size=20>
<br>
电子邮箱:()
<input name="ema" maxlength="28">
<br>
家庭住址:
<input type="text" name="address" size="20">
<br>
<input type="submit" value="提交" name="B1">
<input type="reset" value="全部重写" name="B2">
<br>
</form>
</body>
</html>
运行结果如下图:
自google 06年进入中国,在地图、移动领域的发展速度基本上都是每年几倍的增长。在最新的Android平台开发相关应用程序,如果能深入了解google map 将会对我们Android开发提供很大的帮助以下是我总结的在Android开发中对google map的理解。
1 首先先要获取你的debug keystore位置:
打开Eclipse--->Windows---> preferences--->Android--->Build
查看默认的debug keystore位置,我的是C:\Documents and Settings\sdhbk\android\debugkeystore
2
D:\android-sdk-windows-15_r1\tools>keytool -list -alias androiddebugkey -keysto
re "C:\Documents and Settings\sdhbk\android\debugkeystore" -storepass android
-keypass android
androiddebugkey, 2009-7-25, PrivateKeyEntry,
认证指纹 (MD5): DA:D5:6E:C2:80:D1:0F:0D:F8:2A:58:6A:74:7C:CE:2D
3
打开
填入你的认证指纹(MD5)即可获得apiKey了,结果显示如下:
感谢您注册 Android 地图 API 密钥!
您的密钥是:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4 使用得到的apiKey:
在layout中加入MapView
<comgoogleandroidmapsMapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g" />
或者
<view android:id="@+id/mv"
class="comgoogleandroidmapsMapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:apiKey="0jOkQ80oD1JL9C6HAja99uGXCRiS2CGjKO_bc_g"
/>
5Android在sdk15的预装的add-on中提供了一个Map扩展库comgoogleandroidmaps,利用它你就可以给你的android应用程序增加上强大的地图功能了。这个库的位置在Your-SDK_DIR\add-ons\google_apis-3\libs
一定要在manifestxml中设置全相应的权限,比如:
<uses-permission android:name="androidpermissionACCESS_COARSE_LOCATION" />
<uses-permission android:name="androidpermissionINTERNET" />
要在manifestxml中加上要用的maps库:
<manifest xmlns:android=""
package="comexamplepackagename">
<application android:name="MyApplication" >
<uses-library android:name="comgoogleandroidmaps" />
</application>
</manifest>
需要说明的是这个库不是标准的android sdk的内容,你也可以自己从这里这里下载并放到你的sdk里面。
Maps库分析
Maps库提供了十几个类,具体可以参考这里, 包括Mapview,MapController,MapActivity等。
Mapview是用来显示地图的view, 它也是派生自androidviewViewGroup。
地图可以以不同的形式来显示出来,如街景模式,卫星模式等,具体方法可以参考:
setSatellite(boolean), setTraffic(boolean), and setStreetView(boolean)
MapView只能被MapActivity来创建,这是因为mapview需要通过后台的线程来连接网络或者文件系统,而这些线程要由mapActivity来管理。
需要特别说明的一点是,android 15中,map的zoom采用了built-in机制,可以通过setBuiltInZoomControls(boolean)来设置是否在地图上显示zoom控件。
MapActivity是一个抽象类,任何想要显示MapView的activity都需要派生自MapActivity。并且在其派生类的onCreate()中,都要创建一个MapView实例,可以通过MapView constructor (then add it to a layout View with ViewGroupaddView(View)) 或者通过layout XML来创建。
实例分析
最后,按照惯例,还是用一个小程序来演示一下android中地图功能的开发。主要功能是实现了地图的缩放,添加了菜单,从而可以手动选择地图的显示模式等。
Step 1: 新建一个android project, 注意这里要选择的build target为"Google APIs"
Step 2: 修改menifest文件:
< xml version="10" encoding="utf-8" >
<manifest xmlns:android=""
package="commapprac"
android:versionCode="1"
android:versionName="10">
<uses-permission android:name="androidpermissionACCESS_COARSE_LOCATION" />
<uses-permission android:name="androidpermissionINTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="comgoogleandroidmaps" />
<activity android:name="MapViewPrac2"
android:label="@string/app_name">
<intent-filter>
<action android:name="androidintentactionMAIN" />
<category android:name="androidintentcategoryLAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
Step 3: 修改layout文件,mainxml
< xml version="10" encoding="utf-8" >
<LinearLayout xmlns:android=""
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<comgoogleandroidmapsMapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey=" "
/>
</LinearLayout>
这里需要将api key中的改成你自己申请到的api key
Step 4: 修改代码:
package commapprac;
import comgoogleandroidmapsGeoPoint;
import comgoogleandroidmapsMapActivity;
import comgoogleandroidmapsMapController;
import comgoogleandroidmapsMapView;
import androidappAlertDialog;
import androidappDialog;
import androidcontentDialogInterface;
import androidosBundle;
import androidutilLog;
import androidviewKeyEvent;
import androidviewMenu;
import androidviewMenuItem;
public class MapViewPrac2 extends MapActivity {
private final String TAG = "MapPrac";
private MapView mapView = null;
private MapController mc;
//Menu items
final private int menuMode = MenuFIRST;
final private int menuExit = MenuFIRST+1;
final private int menuCommandList = MenuFIRST + 2;
private int chooseItem = 0;
/ Called when the activity is first created /
@Override
public void onCreate(Bundle savedInstanceState) {
superonCreate(savedInstanceState);
setContentView(Rlayoutmain);
mapView = (MapView)findViewById(Ridmap);
mc = mapViewgetController();
mapViewsetTraffic(true); //
mapViewsetSatellite(false);
mapViewsetStreetView(true);
//GeoPoint gp = new GeoPoint((int)(39269259 1000000), (int)(115255762 1000000));//yixian
GeoPoint gp = new GeoPoint((int)(3995 1000000), (int)(11637 1000000));//beijing
//mcanimateTo(gp);
//mcsetZoom(12);
mcsetCenter(gp);
//to display zoom control in MapView
mapViewsetBuiltInZoomControls(true);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
Logi(TAG,"enter onKeyDown");
return superonKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menuadd(0, menuMode, 0, "Map Mode");
menuadd(0, menuCommandList, 1, "Command List");
menuadd(0, menuExit, 2, "Exit");
return superonCreateOptionsMenu(menu);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
switch(itemgetItemId())
{
case menuMode:
Dialog dMode = new AlertDialogBuilder(this)
//setIcon(Rdrawablealert_dialog_icon)
setTitle(Rstringalert_dialog_single_choice)
setSingleChoiceItems(Rarrayselect_dialog_items2, chooseItem, new DialogInterfaceOnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Logi(TAG, "choose button is "+ whichButton);
chooseItem = whichButton;
/ User clicked on a radio button do some stuff /
}
})
setPositiveButton(Rstringalert_dialog_ok, new DialogInterfaceOnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/ User clicked Yes so do some stuff /
Logi(TAG,"item = "+chooseItem);
switch(chooseItem)
{
case 0:
mapViewsetSatellite(false);
break;
case 1:
mapViewsetSatellite(true);
break;
case 2:
mapViewsetTraffic(true);
break;
case 3:
mapViewsetStreetView(true);
break;
default:
break;
}
}
})
setNegativeButton(Rstringalert_dialog_cancel, new DialogInterfaceOnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/ User clicked No so do some stuff /
}
})
create();
dModeshow();
break;
case menuCommandList:
//create the dialog
Dialog d = new AlertDialogBuilder(this)
setTitle(Rstringselect_dialog)
setItems(Rarrayselect_dialog_items, new DialogInterfaceOnClickListener() {
public void onClick(DialogInterface dialog, int which) {
/ User clicked so do some stuff /
String[] items = getResources()getStringArray(Rarrayselect_dialog_items);
/new AlertDialogBuilder(this)
setMessage("You selected: " + which + " , " + items[which])
show();/
Logi(TAG,"you choose is: " + items[which]);
}
})
create();
//show the dialog
dshow();
break;
case menuExit:
finish();
break;
default:
break;
}
return superonMenuItemSelected(featureId, item);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
关于google map的用法还有待各位Android开发人员在实际开发中的总结!
三个位置有null指针错误,主要问题看类里面的注释
import javaawtFlowLayout;
import javaawtGridLayout;
import javaxswingButtonGroup;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJPanel;
import javaxswingJRadioButton;
import javaxswingJTextField;
public class Liu extends JFrame {
private static final long serialVersionUID = -7384765127315301725L;
JPanel jp1, jp2, jp3, jp4;
JRadioButton jra1, jra2;
ButtonGroup bg;
JLabel jlb1, jlb2;
JTextField[] jtf1 = null, jtf2 = null;
JButton jb1, jb2, jb3;
JLabel jlb3, jlb4, jlb5, jlb6, jlb7, jlb8;
JTextField a, b, c, d, e, f;
public static void main(String[] args) {
Liu just = new Liu();
}
public Liu() {
thissetLayout(new GridLayout(4, 1, 10, 10));
thissetSize(300, 500);
thissetTitle("~~~~");
thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
jp1 = new JPanel();
jp2 = new JPanel();
jp3 = new JPanel();
jp4 = new JPanel();
jp1setLayout(new FlowLayout(FlowLayoutCENTER));
jra1 = new JRadioButton("男", false);
jra2 = new JRadioButton("女", true); //将jra1改成jra2即可
bg = new ButtonGroup();
bgadd(jra1);
bgadd(jra2); //没有jra2实例化
jp1add(jra1);
jp1add(jra2); //没有jra2实例化
jp2setLayout(new GridLayout(2, 7));
jlb1 = new JLabel("Your Pick", JLabelLEFT);
jlb2 = new JLabel("Winner", JLabelLEFT);
jp2add(jlb1);
//jtf1数组初始化为null,没有指定数组长度,下面进行简单修改
jtf1 = new JTextField[6];
for (int i = 0; i < jtf1length; i++) {
jtf1[i] = new JTextField();
jp2add(jtf1[i]);
}
jp2add(jlb2);
//jtf2数组初始化为null,没有指定数组长度,下面进行简单修改
jtf2 = new JTextField[6];
for (int i = 0; i < jtf2length; i++) {
jtf2[i] = new JTextField();
jp2add(jtf2[i]);
}
jp3setLayout(new FlowLayout(FlowLayoutCENTER));
jb1 = new JButton("STOP");
jb2 = new JButton("PLAY");
jb3 = new JButton("RESET");
jp3add(jb1);
jp3add(jb2);
jp3add(jb3);
jp4setLayout(new GridLayout(2, 6, 10, 10));
jlb3 = new JLabel("3of6");
jlb4 = new JLabel("4of6");
jlb5 = new JLabel("5of6");
jlb6 = new JLabel("6of6");
jlb7 = new JLabel("Drawings");
jlb8 = new JLabel("Years");
a = new JTextField();
b = new JTextField();
c = new JTextField();
d = new JTextField();
e = new JTextField();
f = new JTextField();
jp4add(jlb3);
asetEditable(false);
jp4add(a);
jp4add(jlb4);
bsetEditable(false);
jp4add(b);
jp4add(jlb5);
csetEditable(false);
jp4add(c);
jp4add(jlb6);
dsetEditable(false);
jp4add(d);
jp4add(jlb7);
esetEditable(false);
jp4add(e);
jp4add(jlb8);
fsetEditable(false);
jp4add(f);
thisadd(jp1);
thisadd(jp2);
thisadd(jp3);
thisadd(jp4);
thissetVisible(true);
}
}
以上就是关于微信小程序怎么实现日历的年视图功能全部的内容,包括:微信小程序怎么实现日历的年视图功能、想设计一个java小程序,在文本框输入一个数,然后每一秒+1,求给完整代码、java简单小程序编写,就一点点等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)