开发学院手机开发Android 开发 Android 3.0自带的天气预报例子代码 阅读

Android 3.0自带的天气预报例子代码

 2011-03-19 11:57:21 来源:本站整理   
核心提示: private Context mContext; private Cursor mCursor; private int mAppWidgetId; public StackRemoteViewsFactory(Context context, Intent intent) { mContext = co

   private Context mContext;
   private Cursor mCursor;
   private int mAppWidgetId;

   public StackRemoteViewsFactory(Context context, Intent intent) {
     mContext = context;
     mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
         AppWidgetManager.INVALID_APPWIDGET_ID);
   }

   public void onCreate() {
   }

   public void onDestroy() {
     if (mCursor != null) {
       mCursor.close();
     }
   }

   public int getCount() {
     return mCursor.getCount();
   }

   public RemoteViews getViewAt(int position) {
     String city = "Unknown City";
     int temp = 0;
     if (mCursor.moveToPosition(position)) {
       final int cityColIndex = mCursor.getColumnIndex(WeatherDataProvider.Columns.CITY);
       final int tempColIndex = mCursor.getColumnIndex(
           WeatherDataProvider.Columns.TEMPERATURE);
       city = mCursor.getString(cityColIndex);
       temp = mCursor.getInt(tempColIndex);
     }

   final String formatStr = mContext.getResources().getString(R.string.item_format_string);
     final int itemId = (position % 2 == 0 ? R.layout.light_widget_item
         : R.layout.dark_widget_item);
     RemoteViews rv = new RemoteViews(mContext.getPackageName(), itemId);
     rv.setTextViewText(R.id.widget_item, String.format(formatStr, temp, city));

   final Intent fillInIntent = new Intent();
     final Bundle extras = new Bundle();
     extras.putString(WeatherWidgetProvider.EXTRA_CITY_ID, city);
     fillInIntent.putExtras(extras);
     rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);

   return rv;
   }
   public RemoteViews getLoadingView() {
     return null;
   }

   public int getViewTypeCount() {
     return 2;
   }

   public long getItemId(int position) {
     return position;
   }

   public boolean hasStableIds() {
     return true;
   }

   public void onDataSetChanged() {
     if (mCursor != null) {
       mCursor.close();
     }
     mCursor = mContext.getContentResolver().query(WeatherDataProvider.CONTENT_URI, null, null,
         null, null);
   }
}

上一页  1 2 3 4 5 

Tags:Android 自带 天气预报

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接