小编Rah*_*rma的帖子

如何在String的结尾和/或开头保留空格?

我必须从我的资源/值文件连接这两个字符串:

<string name="Toast_Memory_GameWon_part1">you found ALL PAIRS ! on </string>
<string name="Toast_Memory_GameWon_part2"> flips !</string>
Run Code Online (Sandbox Code Playgroud)

我是这样做的:

String message_all_pairs_found = getString(R.string.Toast_Memory_GameWon_part1)+total_flips+getString(R.string.Toast_Memory_GameWon_part2);

Toast.makeText(this, message_all_pairs_found, 1000).show();
Run Code Online (Sandbox Code Playgroud)

但是第一个字符串末尾和第二个字符串开头的空格已经消失(当显示Toast时)......

我该怎么办 ?

我想答案就在这个文档链接的某处

或者它是否像使用&amp ;"&"字符?

android string-concatenation

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

无法从Eclipse,android中删除虚拟设备

我有多个虚拟设备,其中一些无法删除.

错误信息是

android虚拟设备XXX当前正在模拟器中运行,无法删除

当我刚刚重启Ubuntu并且只启动Eclipse时.

android android-emulator

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

Android java.lang.VerifyError?

在我的Android应用程序中,我总是得到VerifyErrors!我无法弄清楚原因.每当我包含一个外部JAR时,我总是在尝试启动我的应用程序时获得VerifyErrors(除了一次,当我包含Apache Log4j时).

我通常通过获取库的源代码并将其添加到我的项目来解决这个问题,但我正在尝试放置GData客户端库.

我可以在源代码中获取它,但它的依赖项(mail.jar,activation.jar,servlet-api.jar)我不能,所以我得到验证错误.我想一劳永逸地找到这个问题的根源.我在互联网上看了一下,但他们似乎都在谈论不完整的类文件?我不知道.

java android gdata verifyerror

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

使用Android Test Framework进行Android AsyncTask测试

我有一个非常简单的AsyncTask实现示例,并且在使用Android JUnit框架测试它时遇到问题.

当我在普通应用程序中实例化并执行它时,它工作得很好.但是当它从任何Android测试框架类(即AndroidTestCase,ActivityUnitTestCase,ActivityInstrumentationTestCase2等)执行时,它表现得很奇怪:

  • doInBackground()正确执行方法
  • 然而,它没有任何调用它的通知方法(onPostExecute(),onProgressUpdate()等) -只是默默忽略它们没有表现出任何错误.

这是非常简单的AsyncTask示例:

package kroz.andcookbook.threads.asynctask;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.Toast;

public class AsyncTaskDemo extends AsyncTask<Integer, Integer, String> {

AsyncTaskDemoActivity _parentActivity;
int _counter;
int _maxCount;

public AsyncTaskDemo(AsyncTaskDemoActivity asyncTaskDemoActivity) {
    _parentActivity = asyncTaskDemoActivity;
}

@Override
protected void onPreExecute() {
    super.onPreExecute();
    _parentActivity._progressBar.setVisibility(ProgressBar.VISIBLE);
    _parentActivity._progressBar.invalidate();
}

@Override
protected String doInBackground(Integer... params) {
    _maxCount = params[0];
    for (_counter = 0; _counter <= _maxCount; _counter++) {
        try { …
Run Code Online (Sandbox Code Playgroud)

junit android

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

改造2:从响应机构获取JSON

我想使用改装2从我的api获取字符串json,使用改装1获取此json时我没有问题,但使用retrofit 2 为我返回null.

这就是我的json的样子

{"id":1,"Username":"admin","Level":"Administrator"}
Run Code Online (Sandbox Code Playgroud)

这是我的API

@FormUrlEncoded
@POST("/api/level")
Call<ResponseBody> checkLevel(@Field("id") int id);
Run Code Online (Sandbox Code Playgroud)

这就是我的代码的样子

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Config.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Api api = retrofit.create(Api.class);
        Call<ResponseBody> call = api.checkLevel(1);
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                JsonObject post = new JsonObject().get(response.body().toString()).getAsJsonObject();
                    if (post.get("Level").getAsString().contains("Administrator")) {

                    }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
            }
        });
Run Code Online (Sandbox Code Playgroud)

我是新手改造2并使用上面的代码,它总是让我的应用程序崩溃因为response.body().toString()返回null.

请指导我如何获取json字符串,以便将其转换为JsonObject.

android json retrofit retrofit2

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

IOException:"收到的身份验证质询为空"(Apache Harmony/Android)

我试图通过Android HttpURLConnection(从中导入org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection)发送GET ,并在收到响应时抛出IOException:

在doRequestInternal()中:"收到的身份验证质询为空"

这个错误意味着什么,是什么导致了这个?我正在向授权标题写OAuth参数,但我也在其他场合这样做,没有问题.

    if (connection == null) {
        connection = (HttpURLConnection) new URL(endpointUrl).openConnection();
        connection.setRequestMethod("GET");
    }

    //... do some OAuth message signing

    connection.connect();

    int statusCode = connection.getResponseCode(); // throws IOException
Run Code Online (Sandbox Code Playgroud)

java android httpurlconnection

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

如何将getsStyledAttributes(int [])与Android的内部主题一起使用

所以我环顾四周,发现它android.R.styleable不再是SDK的一部分,即使它仍然在这里记录.

如果清楚地记录了备选方案的内容,那就不会成为问题.例如,AOSP日历应用程序仍在使用android.R.styleable

// Get the dim amount from the theme   
TypedArray a = obtainStyledAttributes(com.android.internal.R.styleable.Theme);
lp.dimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f);
a.recycle();
Run Code Online (Sandbox Code Playgroud)

那么如果backgroundDimAmount没有得到它int[],怎么会得到android.R.styleable.Theme

obtainStyledAttributes(int [])为了使其与SDK一起使用,我需要注意什么?

android android-xml android-resources android-styles

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

为什么活动中的getApplicationContext().setTheme()不起作用?

我目前很难getApplicationContext().setTheme()在一个活动中调用,我只是想在应用程序范围中应用主题资源而不是代码样式中的活动范围,但问题是这根本不起作用,任何人都可以向这个.

非常感谢.!

他是代码骨架:

public class StartUp extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    /*
     * setTheme(android.R.style.Theme_Black_NoTitleBar_Fullscreen);
     * //that works!
     */
       this.getApplicationContext().setTheme(
            android.R.style.Theme_Black_NoTitleBar_Fullscreen);
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
    }
}
Run Code Online (Sandbox Code Playgroud)

android themes

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

Android M:无法以编程方式删除Wi-Fi AP

在Android M上:我使用下面的代码删除当前连接的AP.

void RemoveConnectedNetwork(){
    int ID=_wifiManager.getConnectionInfo().getNetworkId();
    Log.d("test", "network id = ["+ID+"]");
    boolen ret =_wifiManager.removeNetwork(ID);
    Log.d("test", "removeNetwork return ="+ret);
    _wifiManager.saveConfiguration();
}
Run Code Online (Sandbox Code Playgroud)

但removeNetwork始终返回false.虽然此API在以前的版本中运行良好.任何想法,使用任何其他API可以实现相同的目的吗?

android wifimanager android-wifi

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

嵌套滚动查看不能与recyclerview android顺利滚动

我正在使用嵌套Scrollview来包装recyclerview和其他按钮.它工作得很好,但我注意到,当我滚动它不顺利.请指导如何使滚动顺畅.

 <android.support.v4.widget.NestedScrollView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/scrollView"
                        android:fillViewport="true">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">
                                <Button
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_action_filter"
                                    android:text="Filter"
                                    android:id="@+id/btn_filter"
                                    android:layout_margin="0dp"
                                    android:layout_weight="1"
                                    />
                                <Button
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_action_sortbyt"
                                    android:layout_margin="0dp"
                                    android:text="Sort By"
                                    android:id="@+id/btn_sortby"
                                    android:layout_weight="1"/>
                            </LinearLayout>
                            <android.support.v7.widget.RecyclerView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:id="@+id/lastest_product_list"
                                android:nestedScrollingEnabled="false"
                                android:isScrollContainer="false">
                            </android.support.v7.widget.RecyclerView>
                        </LinearLayout>
                    </android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

android

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