小编Tho*_*omQ的帖子

GSON fromJson 返回 null

我正在寻找解析 JSONobjects,但在使用 fromJson 时我总是得到 null。我确信 inputStream 是有效的,看起来读取器也已初始化并填充,但“响应”不断返回 null,导致致命异常。我期望得到一个包含 3 个字段的“响应”,其中一个字段是结果类型列表,结果中唯一的字段是名称。我究竟做错了什么?

我正在使用以下代码:

    String url = uribuilder.build().toString();

    try {
        HttpRequest httpRequest = requestFactory.buildGetRequest(new GenericUrl(url));
        HttpResponse httpResponse = httpRequest.execute();
        inputStream = httpResponse.getContent();

    } catch (IOException e) {
        e.printStackTrace();
    }

    Gson gson = new Gson();
    Reader reader = new InputStreamReader(inputStream);
    SearchResponse response = gson.fromJson(reader, SearchResponse.class);
    List<Result> resultList = response.results;
Run Code Online (Sandbox Code Playgroud)

搜索响应类:

package com.example.places;

import com.google.gson.annotations.SerializedName;
import java.util.List;

    public class SearchResponse {

        @SerializedName("html_attributions")
        public String html_attributions;

        public List<Result> results;

        @SerializedName("status")
        public String status;

    }
Run Code Online (Sandbox Code Playgroud)

结果类:

package …
Run Code Online (Sandbox Code Playgroud)

android json gson

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

YouTube Android Player API是否有配额?

当我发现它需要YouTube Data API(v3),API密钥时,我计划使用Youtube Android Player API:https://developers.google.com/youtube/android/player/register

Youtube Data API处理大多数youtube的互动,例如getRating,上传视频,评价视频,获取播放列表等,并根据这些操作设置配额:https://developers.google.com/youtube/v3/getting-started#quota&https://developers.google.com/youtube/v3/determine_quota_cost

这些动作都不是视频播放,这就是Android播放器所做的.我也在Android Player API部分找不到任何关于配额的内容.

所以,我的问题有两个方面:为什么播放器API需要数据API,是否有使用播放器API的配额?

android youtube-api android-youtube-api

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

无法使动作栏图标动画化

我正试图让我的Actionbar上的刷新按钮旋转,但是我在使它工作时遇到了一些麻烦.View似乎失去了它的horziontal margin/padding(我没有在任何地方设置),并且不会旋转.我没有得到任何空错误,崩溃或其他任何可能指向正确方向的东西.我究竟做错了什么?任何帮助都会得到很大的帮助.

Main.java:

public class Main extends ActionBarActivity{

...

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.action_refresh:
                refresh();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }


    public void refresh() {

        LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ImageView imageView = (ImageView) inflater.inflate(R.layout.action_refresh, null);

        Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotate);
        rotation.setRepeatCount(Animation.INFINITE);
        imageView.startAnimation(rotation);

        MenuItem item = menu.findItem(R.id.action_refresh);
        item.setActionView(R.layout.action_refresh);

   }
}
Run Code Online (Sandbox Code Playgroud)

menu.xml文件

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:yourapp="http://schemas.android.com/apk/res-auto" >

    <item android:id="@+id/action_refresh"
          android:icon="@drawable/ic_action_refresh"
          android:title="refresh"
          android:actionLayout="@layout/action_refresh"
          yourapp:showAsAction="ifRoom"
          />

    <item
          android:id="@+id/category_spinner_item"
          android:showAsAction="ifRoom"
          android:actionLayout="@layout/action_sort"
          />
</menu>
Run Code Online (Sandbox Code Playgroud)

action_refresh.xml

<?xml version="1.0" encoding="utf-8"?>

<ImageView …
Run Code Online (Sandbox Code Playgroud)

icons android android-animation android-actionbar

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

Android - 更改Custom Spinner的DropDownItem样式

我有一个自定义微调器,我正在尝试替换DropDownSelector中的9补丁背景/三角形.

我只是无法让它正常工作.我最终(白盒子是测试资产):

在此输入图像描述

显示了新的9补丁,但是它弄乱了填充,它看起来像一个Spinner内的Spinner.

这是没有添加9补丁的情况:

在此输入图像描述

这就是我想要的样子,但是后来使用新的9patch而不是旧的,而不是Spinner的Spinner效果.

这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="horizontal"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

   <Spinner xmlns:android="http://schemas.android.com/apk/res/android"
             android:id="@+id/spinner2"
             android:layout_width="wrap_content"
             android:layout_height="fill_parent"
             android:layout_alignParentRight="true"
             android:gravity="center_horizontal"/>

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我将此RelativeLayout添加到Actionbar,并设置自定义微调器适配器:

    SpinnerAdapter mSpinnerAdapter = (new SpinnerCustomAdapterDark(this, R.layout.customSpinnerTitleLayout, categoryNames ));

    spinner = findViewById(R.id.spinner2);

    categorySpinnerMenuitem = (Spinner) spinner;

    categorySpinnerMenuitem.setAdapter(mSpinnerAdapter);
Run Code Online (Sandbox Code Playgroud)

这是设置为适配器的CustomSpinnerTitleLayout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                style="?android:attr/spinnerDropDownItemStyle"
                android:paddingRight="0dp"   >
    <ImageView

            android:id="@+id/spinner_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"
            android:layout_gravity="center"
            android:paddingRight="0dp"
            />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我添加9补丁的主题

<resources>
    <style name="CustomTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:spinnerDropDownItemStyle">@style/customActionBarDropDownStyle</item>
    </style>


    <style name="customActionBarDropDownStyle" parent="@android:style/Widget.Holo.Light.ListView" >
           <item name="android:background">@drawable/spinner9patch</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

我显然做错了什么,但是什么?我试图在第一个布局文件中的Spinner处设置spinnerDropDownItemStyle和spinnerStyle,什么都没做.我在这做错了什么?

提前致谢!!

android android-layout android-spinner android-styles

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