小编Cha*_*ake的帖子

RecyclerView网格具有不同的项目大小

我需要创建一个水平滚动网格,可以分配不同宽度和不同高度的项目.StaggeredGridLayoutManager可以处理不同的宽度,但它不会让我有不同高度的项目.有没有LayoutManager可以做我需要的实现?

android gridlayoutmanager android-recyclerview

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

OnItemSelectedListener.onNothingSelected被调用了吗?

OnItemSelectedListener需要两种方法来实现:onItemSelected和onNothingSelected.我很好奇并尝试在onNothingSelected方法中做一些动作.但是,我无法触发此事件.

它实际上被称为?

android listener android-listview

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

要求用户打开Wi-Fi

我有一个应用程序,几乎总是需要知道用户的位置.

当我需要访问某个位置时,我这样做:

final AlertDialog.Builder builder = new AlertDialog.Builder(
                        MapScreen.this);
builder.setTitle("MyAppName");
builder.setMessage("The location service is off. Do you want to turn it on?");
                builder.setPositiveButton("Enable location",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(
                                    final DialogInterface dialogInterface,
                                    final int i) {
                                startActivity(new Intent(
                                        android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                            }
                        });
builder.setNegativeButton("Continue without location", null);
builder.create().show();
Run Code Online (Sandbox Code Playgroud)

然而,GPS给了我一些不够精确的信息.Wi-Fi总是给我足够的准确性,所以我想要求用户打开Wi-Fi,就像我要求他们打开位置一样.我不想只是打开它,我希望用户得到通知,并手动启用它.

是否有任何意图将WiFi菜单带给用户?

android wifi android-intent

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

将主题应用于v7支持操作栏

我正在使用支持v7库ActionBar在我的应用程序中实现..我在我的styles.xml文件中有这个

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/ActionBarTheme</item>
    </style>
    <style name="ActionBarTheme" parent="android:Widget.ActionBar">
        <item name="android:background">#FFFF0000</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

然而,Eclipse抱怨actionBarStyle道.错误是这一个:

android:actionBarStyle requires API level 11 (current min is 8)

如何将我的主题应用于API级别8-10?

android android-theme android-actionbar android-support-library

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

android.content.ContextWrapper中的NullPointerException

当我尝试getResources().getColor(R.color.yellow)在正常活动中获取颜色时,我得到以下异常:

07-12 11:58:38.019: E/AndroidRuntime(3233): FATAL EXCEPTION: main
07-12 11:58:38.019: E/AndroidRuntime(3233): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.moveinblue.planner/com.moveinblue.planner.controller.plan.PlanDayScreen}: java.lang.NullPointerException
07-12 11:58:38.019: E/AndroidRuntime(3233):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1993)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at android.app.ActivityThread.access$600(ActivityThread.java:132)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1157)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at android.os.Looper.loop(Looper.java:137)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at android.app.ActivityThread.main(ActivityThread.java:4575)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at java.lang.reflect.Method.invokeNative(Native Method)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at java.lang.reflect.Method.invoke(Method.java:511)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-12 11:58:38.019: E/AndroidRuntime(3233):     at dalvik.system.NativeStart.main(Native …
Run Code Online (Sandbox Code Playgroud)

android nullpointerexception android-context android-resources

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

启动 Spotify 意图

我希望我的应用程序打开 Spotify 链接并将人们发送到该应用程序。如果安装了该应用程序,这会产生奇迹:

final Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse("spotify:album:7rt7AxYexFTtdEqaJPekvX"));
Run Code Online (Sandbox Code Playgroud)

但是,在某些情况下还没有安装该应用程序,因此我希望他们从 Google Play 下载它,并具有以下其他意图:

final Intent intent = new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse("https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui"));
Run Code Online (Sandbox Code Playgroud)

但是,我真的希望它直接从 Google Play 安装,而不是让人们选择要打开的应用程序……如果安装了 Google Play。如果缺少 Google Play,我希望他们选择要打开的应用程序(通常是导航器,但无论如何)

有没有办法做到这一点?

android spotify android-intent google-play

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

View.findViewById()返回null

我有这个代码:

private void inflateMenu() {
    if (menu == null) {
        mFanView = (LinearLayout) findViewById(R.id.fanView);
        final View v = LayoutInflater.from(getContext()).inflate(
                R.layout.sidemenu, mFanView);
        menu = (MenuView) v.findViewById(R.id.listViewMenu);
    }
        menu.setColors(backgroundColor, selectedColor, unselectedColor);
}
Run Code Online (Sandbox Code Playgroud)

调试时,v包含一个id等于的MenuView R.id.listViewMenu + 1.当然这会在menu.setColors上抛出一个NPE.

为什么R.id.listViewMenu包含的ID不会导致XML中带有该ID的视图?

我试图清理我的项目,但它仍然保持不变.

编辑:发布请求的文件.

sidemenu.xml

<com.ui.library.slidingmenu.MenuView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listViewMenu"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
Run Code Online (Sandbox Code Playgroud)

编辑:问题解决了.

对于因为findViewById返回null而来到这里的任何人:清理项目.如果它不起作用,请再次清理项目.如果它不起作用,请清除所有项目.直到它工作.如果它不起作用,那么问.

android nullpointerexception findviewbyid

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

Google Maps Android Api 2 - 用于 MapBox 实现的混合 TileProvider / URLTileProvider

我想实现一个具有此功能的 TileProvider:

  • Map要求一个Tile
  • TileProvider 检查所说是否Tile可以离线使用
  • 如果是这样,TileProvider 返回所述Tile
  • 无论可用性如何,TileProvider都会在线检查新磁贴并将其下载到Cache外部存储中。
  • TileProvider为地图提供新的图块,然后地图更新它。

这是我当前的UrlTileProvider实现:

public class MapBoxOnlineTileProvider extends UrlTileProvider {

    private static final String[] FORMATS;

    static {
        final String[] servers = new String[] { "a", "b", "c", "d" };
        final String[] formats = new String[servers.length];
        for (int i = 0; i < servers.length; i++) {
            formats[i] = String.format(
                    "%%s://%s.tiles.mapbox.com/v3/%%s/%%d/%%d/%%d.png",
                    servers[i]);
        }
        FORMATS = formats;
    }

    // ------------------------------------------------------------------------
    // Instance Variables
    // ------------------------------------------------------------------------ …
Run Code Online (Sandbox Code Playgroud)

android caching mapbox google-maps-android-api-2

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

当我在上面放一个长文本时按钮向下移动

我可以解释一下,但我认为一张图片比文字更好地解释了我的问题:

例

这是我的布局.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<include
    android:id="@+id/include1"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    layout="@layout/action_bar" />


<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="top"
    android:padding="8dip" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center" >

            <Button
                android:id="@+id/button1"
                android:layout_width="150dip"
                android:layout_height="150dip"
                android:text="This is a short text" />

            <Button
                android:id="@+id/button2"
                android:layout_width="150dip"
                android:layout_height="150dip"
                android:text="This is a long text to show how the button is moved when it has a long text on it" />
        </TableRow>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/button3"
                android:layout_width="150dip"
                android:layout_height="150dip"
                android:text="Button" /> …
Run Code Online (Sandbox Code Playgroud)

android button

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

DialogFragment上的SupportMapFragment

我需要嵌入SupportMapFragment一个Dialog.这是我能想到的最好的:

public class SupportMapFragmentDialog extends DialogFragment {

    private final SupportMapFragment fragment;

    public SupportMapFragmentDialog() {
        fragment = new SupportMapFragment();
        setTargetFragment(fragment, 1);
    }

    @Override
    public View onCreateView(final LayoutInflater inflater,
            final ViewGroup container, final Bundle savedInstanceState) {
        return fragment.onCreateView(inflater, container, savedInstanceState);
    }

    public SupportMapFragment getFragment() {
        return fragment;
    }

}
Run Code Online (Sandbox Code Playgroud)

但是,当我这样称呼时:

final SupportMapFragmentDialog dialog = new SupportMapFragmentDialog();
dialog.show(getSupportFragmentManager(), "Historico");
Run Code Online (Sandbox Code Playgroud)

我明白了:

在此输入图像描述

如何在Dialog上查看地图?

该应用程序有另一个SupportMapFragment工作奇迹,所以它与配置没有任何关系.

android dialog google-maps-android-api-2 supportmapfragment

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