小编Fei*_* Qu的帖子

Retrofit在同步调用中处理错误

我试图找出在Retrofit同步调用中进行错误处理的正确方法.我知道对于异步调用,Retrofit有一个针对失败案例的回调.但是我应该如何处理同步调用的错误?我的猜测是用try块包装调用并处理catch块中的RetrofitError异常.

android retrofit

19
推荐指数
1
解决办法
5741
查看次数

将片段添加到listview项目中

我想为listview中的每个项目创建一个片段,因为我想将一些逻辑分开.我正在为每个项目使用视图持有者.如果视图不存在,我创建一个新片段并将其添加到容器中.

holder.mMyFragment = new MyFragment(mActivity, this);
mActivity.getSupportFragmentManager().beginTransaction().add(R.id.my_container, holder.mMyFragment).commit();
Run Code Online (Sandbox Code Playgroud)

同样对于每个项目,我调用holder.mMyFragment.setUi(dataSource,position)来根据数据源和位置设置片段的UI.

我遇到的问题是我在片段类的onCreateView方法中初始化片段的UI元素,但是当我将片段添加到项目时它不会被调用.所以后来当我调用setUi()使用片段中的一些UI元素时,它会抱怨NullPointerException.有没有人有建议?谢谢!

android android-listview android-fragments

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

android app链接状态未定义

我按照这个Android教程(http://developer.android.com/training/app-links/index.html)在我的应用程序中实现应用程序链接功能.但是,当我检查链接策略时adb shell dumpsys package d,它显示在"应用程序验证状态"标题下但状态为"未定义",它根本不会显示在"用户0的应用程序链接"标题下.

我做的是在AndroidManifest.xml中:

<activity
            android:name=".activities.SplashActivity"
            android:label="@string/app_name"
            android:noHistory="true" >
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="myhost" />
                <data android:scheme="https" android:host="myhost" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,我使用真正的主机.这个活动是我的应用程序中唯一一个我设置方案和主机的活动.在我的网站上,我添加了这个

[{

    "relation": 

[

    "delegate_permission/common.handle_all_urls"

],
"target": 
{

    "namespace": "android_app",
    "package_name": "mypackage",
    "sha256_cert_fingerprints": 

            [
                "myfingerprint1",
                "myfingerprint2"
            ]
        }
    }

]
Run Code Online (Sandbox Code Playgroud)

我试图通过https://myhost/.well-known/assetlinks.json从浏览器访问它,它可以工作.但是,在我安装应用程序后,等待一段时间然后运行adb shell dumpsys package d,它只是说"未定义".顺便说一下,我在M设备上测试它.

android

9
推荐指数
1
解决办法
1263
查看次数

如何在 Android 中设置自定义搜索建议列表的样式

我根据本教程实现了内容提供者的自定义建议;它有效,但是我在设置建议列表的样式时遇到问题。我目前拥有的建议列表有黑色背景和白色文本。我想将其更改为白色背景和黑色文本。我在网上做了一些搜索,并在 style.xml 文件中尝试了类似的东西:

<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
    <item name="suggestionRowLayout">@layout/list_item_search_suggestion</item>
</style>
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="searchViewStyle">@style/MySearchViewStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的 list_item_search_suggestion 看起来像这样:

    <?xml version="1.0" encoding="utf-8"?>
<TextView
    android:id="@android:id/text1"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:gravity="center_vertical"
    android:minHeight="56dp"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@android:color/black"
    tools:text="Blah blah blah"/>
Run Code Online (Sandbox Code Playgroud)

但是,当我运行应用程序并搜索某些内容时,它会在建议列表出现之前崩溃。我从 SuggestionsAdapter 中的 newView 方法得到 NullPointerException。这个 SuggestionAdapter 来自 SDK,我没有实现我自己的适配器。我只是实现了内容提供程序并在 searchable.xml 中进行了设置。堆栈轨道也是这样的:

06-15 21:11:09.253    4063-4063/com.tophatter E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.tophatter, PID: 4063
java.lang.NullPointerException
        at android.support.v7.widget.SuggestionsAdapter.newView(SuggestionsAdapter.java:249)
        at android.support.v7.widget.SuggestionsAdapter.getView(SuggestionsAdapter.java:453)
        at android.widget.AbsListView.obtainView(AbsListView.java:2255)
        at android.widget.ListPopupWindow$DropDownListView.obtainView(ListPopupWindow.java:1585)
        at android.widget.ListView.measureHeightOfChildren(ListView.java:1263)
        at android.widget.ListPopupWindow.buildDropDown(ListPopupWindow.java:1167)
        at android.widget.ListPopupWindow.show(ListPopupWindow.java:554)
        at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1096)
        at android.widget.AutoCompleteTextView.updateDropDownForFilter(AutoCompleteTextView.java:971) …
Run Code Online (Sandbox Code Playgroud)

android android-actionbar searchview

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

如何通知用户他的Windows Phone操作系统不支持该应用程序

我制作了一个Windows Phone应用程序,并希望将其发布到市场.但是,它仅支持Windows OS 7.5.它不支持Windows 0S 7.0.那么我应该如何通知用户呢?App市场会在尝试下载应用时通知用户吗?谢谢!

c# silverlight marketplace windows-phone-7

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

给定一个int数组和一个数n,计算使用整数求和的方法数

我在面试准备中看到了这个问题.

给定一个int数组和一个数n,计算使用整数求和的方法数

以下代码是我的解决方案.我试图通过递归来解决这个问题.子问题是针对数组中的每个int,我们可以选择与否.

public static int count(List<Integer> list, int n) {
    System.out.print(list.size() + ", " + n);
    System.out.println();
    if (n < 0 || list.size() == 0)
      return 0;
    if (list.get(0) == n)
      return 1;
    int e = list.remove(0);
    return count(list, n) + count(list, n - e);
  }
Run Code Online (Sandbox Code Playgroud)

我尝试使用[10,1,2,7,6,1,5]进行整数,并将n设置为8.结果应为4.但是,我得到0.我试图打印每层上的内容堆栈的调试,如代码中所示.以下是我所拥有的:

7, 8
6, 8
5, 8
4, 8
3, 8
2, 8
1, 8
0, 8
0, 3
0, 7
0, 2
0, 1
0, 6
0, 7
0, -2
Run Code Online (Sandbox Code Playgroud)

这个结果让我很困惑.我认为它从开始到(0,3)看起来正确.从(0,7)开始,我看起来不对.我期待(1,7)那里.因为如果我理解正确的话,这就是对堆栈底层的第二个count(list,n - …

algorithm recursion

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

在参考中找不到System.Drawing.dll

我有一个奇怪的问题.我正在使用Visual Studio 2010 Express for Windows Phone并想要引用System.Drawing.dll.我在项目中右键单击"引用"并单击"添加引用...",但是,我在.NET选项卡下找不到System.Drawing.dll.有什么想法吗?谢谢!

.net c# visual-studio windows-phone-7

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