小编and*_*one的帖子

如何在活动之间传递drawable

如何在活动之间传递图像,可绘制类型?

我试试这个:

private Drawable imagen;

Bundle bundle = new Bundle();
bundle.putSerializable("imagen", (Serializable) unaReceta.getImagen());
Intent myIntent = new Intent(v.getContext(), Receta.class);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);
Run Code Online (Sandbox Code Playgroud)

但它报告了我的一个例外:

java.lang.ClassCastException: android.graphics.drawable.BitmapDrawable
Run Code Online (Sandbox Code Playgroud)

android drawable android-activity

30
推荐指数
1
解决办法
4万
查看次数

按日期排序NSFetchRequest,然后按字母顺序排序

我想先按NSFetchRequest日期订购,然后如果它按名称匹配同一天的订单.我使用a UIDatePicker来获取日期并使用Core Data保存它

[self.managedObject setValue:self.datePicker.date forKey:self.keypath];
Run Code Online (Sandbox Code Playgroud)

并排序NSFetchRequest如下:

NSSortDescriptor *sortDescriptor1 = [[NSSortDescriptor alloc] initWithKey:@"day" ascending:NO];
NSSortDescriptor *sortDescriptor2 = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor1, sortDescriptor2, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
Run Code Online (Sandbox Code Playgroud)

现在我的问题是它只按日期排序,而不是按名称排序,因为UIDatePicker存储在Core Data中的日期也是小时.因此,即使在同一天,由于小时不同,在同一天没有按"名称"排序.那么如何在核心数据中只保存日期mm/dd/yyyy而不是de小时UIDatePicker

或者您是否考虑过任何其他解决方案?

sorting iphone date uidatepicker nsfetchrequest

12
推荐指数
2
解决办法
8111
查看次数

Android:无法销毁活动

我使用以下代码删除每个视图组上的子项:

protected void onDestroy() {
    super.onDestroy();
    this.liberarMemoria();
}

public void liberarMemoria(){
     imagenes.recycleBitmaps(); 
     this.unbindDrawables(findViewById(R.id.RelativeLayout1));
     System.gc();
}
private void unbindDrawables(View view) {
    if (view.getBackground() != null) {
    view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup) {
    for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
        unbindDrawables(((ViewGroup) view).getChildAt(i));
    }
    ((ViewGroup) view).removeAllViews();
    }
}
Run Code Online (Sandbox Code Playgroud)

其中视图:R.id.RelativeLayout1是ListView.

但这样做我有例外:

E/AndroidRuntime(582): java.lang.RuntimeException: Unable to destroy activity {...}: java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView
Run Code Online (Sandbox Code Playgroud)

我怎么解决这个问题?

android destroy android-activity

10
推荐指数
2
解决办法
1万
查看次数

共享图片,但没有文件扩展名

我想共享一个在我自己的应用程序中的图像,我使用以下代码:

Intent shareIntent =  new Intent(android.content.Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"package"/drawable/" + card_name));
shareIntent.setType("image/jpg");
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_app_via)));
Run Code Online (Sandbox Code Playgroud)

没有问题,但如果我将图像发送到电子邮件并下载它,图像没有extension.jpg,因此无法打开.

我怎么做jpg扩展到图像?

android share image

7
推荐指数
1
解决办法
680
查看次数

以编程方式更改AppBarLayout主题

首先我通过xml设置AppBarLayout主题:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/MyTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/MyTheme.PopupOverlay"
        app:titleTextAppearance="@style/MyTheme.Toolbar.Title" />
Run Code Online (Sandbox Code Playgroud)

其中@style/MyTheme.AppBarOverlay包含:

<style name="MyTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="colorPrimary">@drawable/toolbar_background</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是在某些情况下我想以编程方式更改它而不更改活动的主题(仅限AppBarLayout的主题).

我试过这两种方法没有成功:

  1. 第一:

    ActionBar actionBar = getSupportActionBar(); actionBar.getThemedContext().setTheme(R.style.MyTheme_AppBarOverlay_2);

  2. 第二:

    AppBarLayout mAppBar = (AppBarLayout) findViewById(R.id.appbar); mAppBar.getContext().setTheme(R.style.MyTheme_AppBarOverlay_2);

android android-actionbar android-toolbar android-appbarlayout

5
推荐指数
1
解决办法
2763
查看次数

在iOS 5中使用弃用的方法

我最近将我的应用程序从iOS3升级到iOS5.在编译时,我有几个使用弃用方法的警告.

两个问题:

1-在使用iOS 5的iPhone中运行应用程序时是否会出现问题?

2-如果我没有更新方法,Apple会在将应用程序上传到AppStore时接受吗?

iphone methods deprecated ios ios5

4
推荐指数
2
解决办法
4572
查看次数