当前位置:  编程技术>移动开发
本页文章导读:
    ▪Handler的施用        Handler的使用 class LoginHander extends Handler { private static final int MSG_DIALOG_LOADING = 1; private static final int MSG_DIALOG_CANCEL = 2; private static final int MSG_SHOW_TOAST = 3; public void actionShowProgressDlg(int id){ .........
    ▪ titlebar 标题栏展示进度条        titlebar 标题栏显示进度条 @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.your_layout); }然后你可任意调用 setPr.........
    ▪ 桌面小部件旋转屏后失效有关问题       桌面小部件旋转屏后失效问题 ppWidgetProvider @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if(intent.getAction().equals("test.CLICK")) { CallTestMethod(context.........

[1]Handler的施用
    来源: 互联网  发布时间: 2014-02-18
Handler的使用
class LoginHander extends Handler {
		private static final int MSG_DIALOG_LOADING = 1;
		private static final int MSG_DIALOG_CANCEL = 2;
		private static final int MSG_SHOW_TOAST = 3;
		
		public void actionShowProgressDlg(int id){
			android.os.Message msg = new android.os.Message();
	        msg.what = MSG_DIALOG_LOADING;
	        msg.arg1 = id;
	        sendMessage(msg);
		}

		public void actionHideProgressDlg(int id){
			android.os.Message msg = new android.os.Message();
	        msg.what = MSG_DIALOG_CANCEL;
	        msg.arg1 = id;
	        sendMessage(msg);
		}
		
		public void actionShowToast(final String str) {
			android.os.Message msg = new android.os.Message();
	        msg.what = MSG_SHOW_TOAST;
	        msg.obj = str;
	        sendMessage(msg);
		}
		
		@Override
public void handleMessage(Message msg) {
			switch (msg.what) {
			case MSG_DIALOG_LOADING:
				showDialog(msg.arg1);
				break;
			case MSG_DIALOG_CANCEL:
				dismissDialog(msg.arg1);
				break;
			case MSG_SHOW_TOAST:
Toast.makeText(Login.this, (String)msg.obj, Toast.LENGTH_LONG).show();
				break;
			default: 
				super.handleMessage(msg);
				break;
			}
		}
	
	}

    
[2] titlebar 标题栏展示进度条
    来源: 互联网  发布时间: 2014-02-18
titlebar 标题栏显示进度条

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.your_layout);
}然后你可任意调用

setProgressBarIndeterminateVisibility(true);

setProgressBarIndeterminateVisibility(false);

    
[3] 桌面小部件旋转屏后失效有关问题
    来源: 互联网  发布时间: 2014-02-18
桌面小部件旋转屏后失效问题
ppWidgetProvider

@Override
public void onReceive(Context context, Intent intent)    
{
    super.onReceive(context, intent);

    if(intent.getAction().equals("test.CLICK"))
    {
        CallTestMethod(context);
    }
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
    int[] appWidgetIds) {
    final int N = appWidgetIds.length;

    // Perform this loop procedure for each App Widget that belongs to this provider
    for (int i=0; i<N; i++) {
        int appWidgetId = appWidgetIds[i];

        RemoteViews views=new RemoteViews(context.getPackageName(), R.layout.widget);            
        Intent clickintent=new Intent("test.CLICK");
        PendingIntent pendingIntentClick=PendingIntent.getBroadcast(context, 0, clickintent, PendingIntent.FLAG_UPDATE_CURRENT);
        views.setOnClickPendingIntent(R.id.change_mode, pendingIntentClick);
        SetInitialLayout(context);
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}

 上述代码在旋转屏后失效,解决办法是

@Override
public void onReceive(Context context, Intent intent)    
{
    super.onReceive(context, intent);
    if(intent.getAction().equals("test.CLICK"))
    {
        getIntent().putExtra("Just received click", true);
        CallTestMethod(context);
    }
}

或者呢 如下使用

@Override
 public void onUpdate(Context context, AppWidgetManager appWidgetManager,
   int[] appWidgetIds) {
  context.startService(new Intent(context, MyUpdateService.class));
 }

public static class MyUpdateService extends Service 
 { 
  @Override
  public void onCreate() {
   super.onCreate();
  }

  @Override
  public void onDestroy() {
   super.onDestroy();
  }

  @Override 
  public void onStart(Intent intent, int startId) 
  { 
   super.onStart(intent, startId); 
   // Update the widget 
   RemoteViews remoteView = buildRemoteView(this); 

   // Push update to homescreen 
   pushUpdate(remoteView); 

             } 

  public RemoteViews buildRemoteView(Context context) 
  { 
   int layoutID = R.layout.widget;
   if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
    layoutID = R.layout.widget_landscape;
   }
                                    //Here is where you set your onclick listeners again since the remote views need to be refreshed/recreated
   RemoteViews updateView = new RemoteViews(context.getPackageName(),layoutID); 
   // Create an Intent to launch ExampleActivity
   Intent intent = new Intent(this, yourAndroidActivity.class);
   PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
     intent, 0);

   updateView.setOnClickPendingIntent(R.id.yourClickableViewHere, pendingIntent);

   return updateView; 
  } 

  @Override 
  public void onConfigurationChanged(Configuration newConfig) 
  { 
   RemoteViews remoteView = buildRemoteView(this); 
    // Push update to home screen 
   pushUpdate(remoteView); 
  } 

  private void pushUpdate(RemoteViews updateViews) 
  { 
   ComponentName myWidget = new ComponentName(this, YourAppWidgetbackground-color: transparent; margin: 0px; color: #000000; font-size: 14px; vertical-align: bas
 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3