当前位置: 编程技术>移动开发
本页文章导读:
▪jquery mobile的小TIPS聚合1 jquery mobile的小TIPS集合1
jquery mobile的确是个好东西,新推出的BEATA版,更能适应更多的浏览器了,下面是小结下相关的TIPS,部分是收集的:1) 显示和隐藏BACK这个默认按钮 $(document).b.........
▪ widget开发范例代码 widget开发实例代码
其实创建一个widget很简单。这里就做了一个简单的demo,作为学习记录。
首先在AndroidManifest.xml中添加如下部分
一个widget其实就是一个receiver
<receiver android:name="WidgetProvi.........
▪ SharedPreferences保存数据和在别的应用程序里面怎么访问 SharedPreferences保存数据和在别的应用程序里面如何访问
package cn.itcast.preferences;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Edi.........
[1]jquery mobile的小TIPS聚合1
来源: 互联网 发布时间: 2014-02-18
jquery mobile的小TIPS集合1
jquery mobile的确是个好东西,新推出的BEATA版,更能适应更多的浏览器了,下面是
小结下相关的TIPS,部分是收集的:
1) 显示和隐藏BACK这个默认按钮
$(document).bind("mobileinit", function () { $.mobile.page.prototype.options.addBackBtn = true;
});
2) 修改back button的文字
$(document).bind("mobileinit", function () {$.mobile.page.prototype.options.backBtnText = "previous";});
3)在代码中动态隐藏dialog中的close按钮
$('[data-role=dialog]div[id="YourDiaogdivID"]').live('pagecreate', function (event) {
$("a[data-icon='delete']").hide();
});
4) 刷新一个checkbox
$("select#foo").parent().contents().children('.ui-btn-text').text('Your Text Here');
5) 显示或隐藏日期器
$(".ui-datepicker").hide();
$(".ui-datepicker").show();
6)
jquery mobile的确是个好东西,新推出的BEATA版,更能适应更多的浏览器了,下面是
小结下相关的TIPS,部分是收集的:
1) 显示和隐藏BACK这个默认按钮
$(document).bind("mobileinit", function () { $.mobile.page.prototype.options.addBackBtn = true;
});
2) 修改back button的文字
$(document).bind("mobileinit", function () {$.mobile.page.prototype.options.backBtnText = "previous";});
3)在代码中动态隐藏dialog中的close按钮
$('[data-role=dialog]div[id="YourDiaogdivID"]').live('pagecreate', function (event) {
$("a[data-icon='delete']").hide();
});
4) 刷新一个checkbox
$("select#foo").parent().contents().children('.ui-btn-text').text('Your Text Here');
5) 显示或隐藏日期器
$(".ui-datepicker").hide();
$(".ui-datepicker").show();
6)
[2] widget开发范例代码
来源: 互联网 发布时间: 2014-02-18
widget开发实例代码
其实创建一个widget很简单。这里就做了一个简单的demo,作为学习记录。
首先在AndroidManifest.xml中添加如下部分
一个widget其实就是一个receiver
<receiver android:name="WidgetProvider"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <intent-filter> <action android:name="org.yangzc.widget.fresh"></action> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/appwidget_provider"></meta-data> </receiver>
WidgetProvider.java部分代码如下:
provider需要继承自AppWidgetProvider,这个例子是定时更新widget内容。
package org.yangzc.widget; import java.util.Calendar; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.util.Log; import android.widget.RemoteViews; public class WidgetProvider extends AppWidgetProvider { private String fresh = "org.yangzc.widget.fresh"; private Context context; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) { Log.d("d","onUpdate"); // super.onUpdate(context, appWidgetManager, appWidgetIds); this.context = context; for(int i=0; i<appWidgetIds.length; i++){ int appWidgetId = appWidgetIds[i]; RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main); views.setTextViewText(R.id.thread, i+":Sdfsdfsdf"); appWidgetManager.updateAppWidget(appWidgetId, views); } RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main); views.setTextViewText(R.id.thread, ":Sdfsdfsdf"); appWidgetManager.updateAppWidget(appWidgetIds[0], views); new MyThread().start(); } @Override public void onReceive(Context context, Intent intent) { Log.d("d","onReceive"); super.onReceive(context, intent); String action = intent.getAction(); if(fresh.equals(action)){ RemoteViews views = new RemoteViews(context.getPackageName(),R.layout.main); Calendar cal=Calendar.getInstance(); System.out.println(cal.getTime().toLocaleString()); views.setTextViewText(R.id.thread, cal.getTime().toLocaleString()); ComponentName thisWidget = new ComponentName(context,WidgetProvider.class); AppWidgetManager.getInstance(context).updateAppWidget(thisWidget, views); } } class MyThread extends Thread{ public MyThread(){ } @Override public void run() { while(true){ try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } Intent intent = new Intent(fresh); context.sendBroadcast(intent); } } } }
main.xml
布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/thread" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>
appwidget_provider.xml
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" android:minHeight="72px" android:minWidth="72px" android:updatePeriodMillis="3800000" android:initialLayout="@layout/main"> </appwidget-provider>
[3] SharedPreferences保存数据和在别的应用程序里面怎么访问
来源: 互联网 发布时间: 2014-02-18
SharedPreferences保存数据和在别的应用程序里面如何访问
package cn.itcast.preferences; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity { private EditText nameText; private EditText ageText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); nameText = (EditText)findViewById(R.id.name); ageText = (EditText)findViewById(R.id.age); Button button = (Button)this.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = nameText.getText().toString(); String age = ageText.getText().toString(); SharedPreferences preferences = getSharedPreferences("itcast", Context.MODE_WORLD_READABLE); Editor editor = preferences.edit(); editor.putString("name", name); editor.putInt("age", new Integer(age)); editor.commit(); Toast.makeText(MainActivity.this, R.string.success, 1).show(); } }); Button resumebutton = (Button)this.findViewById(R.id.resume); resumebutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences preferences = getSharedPreferences("itcast", Context.MODE_PRIVATE); String name = preferences.getString("name", ""); int age = preferences.getInt("age", 20); nameText.setText(name); ageText.setText(String.valueOf(age)); } }); } }
package cn.itcast.other; import android.content.Context; import android.content.SharedPreferences; import android.test.AndroidTestCase; import android.util.Log; public class AccessOtherAppPreferenceTest extends AndroidTestCase { private static final String TAG = "AccessOtherAppPreferenceTest"; public void testAccessOtherAppPreference() throws Throwable{ //String path = "/data/data/cn.itcast.preferences/shared_prefs/itcast.xml"; //File file = new File(path); // SAX来完成xml文件的解析,才能得到参数 Context otherContext = getContext().createPackageContext("cn.itcast.preferences", Context.CONTEXT_IGNORE_SECURITY); SharedPreferences preferences = otherContext.getSharedPreferences("itcast", Context.MODE_PRIVATE); String name = preferences.getString("name", ""); int age = preferences.getInt("age", 20); Log.i(TAG, "name="+ name + ",age="+ age); } }
最新技术文章: