小编Pri*_*off的帖子

如何从不使用外部类名的内部类中获取外部类的引用?

以下是示例代码:

Class SomeClass extends Activity {
    public void someMethod() {
        Runnable r = new Runnable() {
            public void run() {
                Intent service = new Intent(SomeClass.this, SomeOtherClass.class);
                // ...
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如何将代码更改为不使用SomeClass(in new Intent(SomeClass.this, ...))?我想将此示例放在多个类中,我不希望每次都使用不同的类名.

java android

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

排序一副纸牌

给一副N纸牌。您必须使用以下允许的操作对它们进行排序:

  1. 您可以看到前2张卡。
  2. 您可以交换它们。
  3. 您可以在底部插入顶部。

有任何想法吗?

sorting algorithm playing-cards data-structures

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

Java将Json字符串转换为数组

我有一个Json字符串,我试图将其转换为Java中的数组.

public void DisplaySubjects(String subjects)
     {
         JSONObject jsonResponse;
         jsonResponse = new JSONObject(subjects));
Run Code Online (Sandbox Code Playgroud)

就我而言.我甚至不确定我是否必须先创建一个对象.

我将需要做什么eventuallay将它附加到Android应用程序中的ArrayAdapter.

谢谢

java android json

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

如何在Android中检索当前系统的屏幕亮度值?

我正在尝试创建一个将以编程方式设置android设备亮度的应用程序。我设法使用以下代码更改设备的亮度:

BackLightValue = (float)arg1/100;
BackLightSetting.setText(String.valueOf(BackLightValue));

WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.screenBrightness = BackLightValue;
getWindow().setAttributes(layoutParams);
Run Code Online (Sandbox Code Playgroud)

我已使用以下代码检索当前的系统亮度值:

try {
    BackLightValue = android.provider.Settings.System.getInt(getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS);
} catch(Exception e) {}
Run Code Online (Sandbox Code Playgroud)

上面的代码应该给我当前的亮度设置值,但是当我启动一个应用程序时,它会显示默认值50%。

怎么了?

android brightness

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

将TextView中心与水平对齐并将底部对齐

在这个布局中,我有两个视图 - 右下角的ImageButton和中间底部的TextView.当android:visibility两个视图都设置为visible- 时,所有视图都根据需要对齐.但是,如果我将android:visibilityImageButton 设置为gone- EditText转到布局的左边缘.

问题:

1)为什么会这样??

2)如何实现不改变EditText设置ImageButton可视性的地方gone?我需要获得与左图相同的布局(见下文),但没有ImageButton.(我知道,一种可能性是设置visibilitygone,但是invisible,但我对解决方案更感兴趣visibility = "gone")

Ps:前两个布局 - RelativeLayout并且FrameLayout是强制性的 - 它们用于其他东西,我刚刚删除了与问题无关的所有内容.

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

    <FrameLayout
        android:id="@+id/mForSearchFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/mForAdMediation"
        android:layout_alignWithParentIfMissing="true" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/mSearchEditText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:ems="5"
                android:imeOptions="actionSearch"
                android:inputType="text"
                android:visibility="visible" >

                <requestFocus />
            </EditText>

            <ImageButton
                android:id="@+id/mSearchButton"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_alignParentBottom="true" …
Run Code Online (Sandbox Code Playgroud)

xml android relativelayout android-layout

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

Java:类问题

我有以下代码

class Demo {
    static int a = 0;
    static int b = 1;
    static {
        a = ++b;
    }

    void gam(int x) {
        a = a * x;
        b = b * x;
    }
}

class Test {
    public static void main(String[] args) {
        Demo d1 = new Demo();
        Demo d2 = new Demo();
        d1.a++;
        d2.a--;
        System.out.println(d1.a + " " + d1.b + " " + d2.a + " " + d2.b);
    }
}
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚为什么d1.a是2.不应该是3吗?从而a=++b使它成为2并d1.a++使其成为3?

java static-members

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