小编Ali*_*Ali的帖子

使用iOS中的objectForKey使用NSJSONSerialization类解析json

我是iOS开发的新手.我使用此代码连接到我的REST Web服务并以Json格式获取数据.

    NSString *url=@"URL_Address";

    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];

    NSURLResponse *resp = nil;
    NSError *err = nil;

    NSData *response = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: &resp error: &err];

//    NSString * theString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 
//    NSLog(@"response: %@", theString);

    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: response options: NSJSONReadingMutableContainers error: &err];

    if (!jsonArray) {
        NSLog(@"Error parsing JSON: %@", err);
    } else {
        for(NSDictionary *item in jsonArray) {
            NSLog(@" %@", item);
            NSLog(@"---------------------------------");
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在我想把它们分开objectForKey.我在循环中使用了这段代码:

NSString *name = [item …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios ios5 nsjsonserialization

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

如果活动停止,则重新创建传递给getIntent()的内容

当我通过Intent BundleExtra创建它时,我将一个布尔值传递给我的Activity.现在查看活动生命周期,如果我的活动停止(onStop),那么另一个应用程序需要内存,以便应用程序进程被终止,然后用户导航到activity(onCreate).最后的onCreate会包含我传递的原始布尔值吗?我想如果我想保存布尔值我需要保存它OnSaveInstanceState,对吗?

android android-intent

5
推荐指数
2
解决办法
1322
查看次数

在Android或REST中从Lat/Long生成地址

我正在使用与REST Web服务交互的Android应用程序.我们在手机中有一项功能,以便在Google原生地图中选择一个位置,然后发送到服务器.

出于某种原因,我们需要获取网站中该点的地址以打印出来.

如果我们使用Geocoder从手机中获取Latitude和Longtitude的地址并将其发送到REST,我们需要在手机中消耗一些内存,数据和带宽.

如果我们在REST中执行此操作,因为应该对使用该应用程序的许多用户执行此操作,该过程可能非常耗时.(这是我们的REST开发人员所相信的)

你能帮我个点意见吗?哪个想法更好,为什么?

rest android web-services web-applications

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

在 Android 项目中使用 Espresso 2.0 + Roboelectric

我已经进行了一系列 Roboelectric 测试。我想添加最近推出的Espresso 2.0 。

Roboelectric引入了decard-gradle模板项目来解决Roboelectric和Espresso一起使用的问题。但解决方案适用于 Espresso 1.1,现已弃用。

这是我的 build.gradle 文件的一部分,以便在我拥有 Roboelectric 以及遵循Espresso 2.0 指令时使用 Espresso 2.0 :

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'org.robolectric:robolectric-gradle-plugin:0.13.2'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'robolectric'

android {
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
    }
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        versionCode 1
        versionName '1.0'
        minSdkVersion 9
        targetSdkVersion 21
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}

robolectric {
    include …
Run Code Online (Sandbox Code Playgroud)

android gradle robolectric android-espresso

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

矩形无界涟漪效果

我知道我们可以简单地通过设置?android:attr/selectableItemBackgroundBorderless背景属性来获得视图的无限涟漪效果。

我们也可以简单地使用我们自己的波纹绘制来自定义颜色:

<!-- An unbounded blue ripple. --/>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/blue" />
Run Code Online (Sandbox Code Playgroud)

结果是一个具有涟漪效应的无界圆,从中心涟漪到角落。

我尝试使用 Rectangle 而不是 Circle 来构建相同的效果,但我永远找不到相同的效果。例如,我尝试使用掩码视图进行以下操作:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:colorControlHighlight">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="?android:colorAccent" />
        </shape>
    </item>
</ripple>
Run Code Online (Sandbox Code Playgroud)

更多示例:http : //blog.stylingandroid.com/ripples-part-3/

结果是一个矩形,但不是unbounded。它将被绑定到视图边界(如文档中的掩码所解释的)以及涟漪效应是不同的(对我来说在 Android-M 预览版中)

我想知道是否有任何解决方案可以简单地构建具有与默认无界波纹相同波纹效果的无界矩形(如我上面所解释的)?

或者为了解决我应该去自定义视图的问题?

android android-custom-view

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

执行packageReleaseJar后,自动将versionCode增加1

我在build.gradle的android标签中有以下内容以增加versionCode:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    def versionPropsFile = file('version.properties')

    if (versionPropsFile.canRead()) {
        def Properties versionProps = new Properties()

        versionProps.load(new FileInputStream(versionPropsFile))
        List<String> runTasks = gradle.startParameter.getTaskNames();
        def value = 0
        for (String item : runTasks)
            if (item.contains("packageReleaseJar")) {
                value = 1;
            }

        def code = versionProps['VERSION_CODE'].toInteger() + value
        versionProps['VERSION_CODE'] = code.toString()
        versionProps.store(versionPropsFile.newWriter(), null)

        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 22
            versionCode code
            versionName version
            testApplicationId 'se.android.instrumenttest'
            testInstrumentationRunner 'se.android.Runner'

            printf("\n--------" + "VERSION DATA--------"
                    + "\n" + "- CODE: " …
Run Code Online (Sandbox Code Playgroud)

android gradle android-gradle-plugin

5
推荐指数
0
解决办法
375
查看次数

在Android中以编程方式设置自定义属性

我有以下自定义属性:

<declare-styleable name="BoxGridLayout">
        <attr name="numColumns" format="integer" />
        <attr name="numRows" format="integer" />
        <attr name="separatorWidth" format="dimension" />
        <attr name="separatorColor" format="color" />
        <attr name="equalSpacing" format="boolean" />
    </declare-styleable>
Run Code Online (Sandbox Code Playgroud)

在自定义视图中,我们可以获得如下自定义属性:

TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
                R.styleable.BoxGridLayout,
                0,
                defStyleAttr);

        try {
            mStrokeWidth = a.getDimensionPixelSize(R.styleable.BoxGridLayout_separatorWidth, DEFAULT_STROKE_WIDTH);
            mStrokeColor = a.getColor(R.styleable.BoxGridLayout_separatorColor, DEFAULT_COLOR);
            mColumnCount = a.getInteger(R.styleable.BoxGridLayout_numColumns, DEFAULT_COLUMN_COUNT);
            mRowCount = a.getInteger(R.styleable.BoxGridLayout_numRows, DEFAULT_ROW_COUNT);
            mEqualSpacing = a.getBoolean(R.styleable.BoxGridLayout_equalSpacing, DEFAULT_EQUAL_SPACING);
        } finally {
            a.recycle();
        }
Run Code Online (Sandbox Code Playgroud)

我们需要在xml视图布局中设置它们:

<com.github.ali.android.client.customview.view.PadLayout
        android:id="@+id/padLayout"
        style="@style/PadLayoutStyle"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        custom:numColumns="3"
        custom:numRows="4"
        custom:separatorColor="@color/dialer_theme_color"
        custom:separatorWidth="1dp">
Run Code Online (Sandbox Code Playgroud)

我们如何在java代码中以编程方式设置这些自定义属性,而不是通过xml中的自定义命名空间?

android android-custom-view android-layout

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

限制UITableView的滚动

我有一个TableViewController:

在此输入图像描述

如你所见,我在顶部有自己的自定义栏.UITable View只是static一个,我在UITableView的顶部添加了一个视图.

问题是,当我将TableView滚动到顶部时,它变得像波纹管图像,我不想要它.是否有任何简单的代码,我可以限制tableView的滚动?

在此输入图像描述

iphone xcode objective-c interface-builder ios

4
推荐指数
2
解决办法
6894
查看次数

流程构建中的使用在Android Studio v1.3中消失了

我最近在Beta版频道将我的Android Studio更新为1.3,我注意到Use in process-build编译器 - > Gradle设置菜单已经消失了.那么我想知道如何在考虑一个已知问题的情况下调试我的Robolectric测试,如在Android Studio中运行Robolectric测试时的如何调试中所述?http://www.culmination.org/2014/03/debugging-during-robolectric-test-execution-in-android-studio/

我收到java.net.SocketException "Socket closed"错误,我不知道如何禁用Use in process-build.

问题跟踪

android robolectric android-studio

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

从模块中的 build.gradle 删除项目根目录中的文件夹

我使用以下任务删除当前模块中的文件夹:

task clearJar(type: Delete) {
    delete 'build/generated/'
}
Run Code Online (Sandbox Code Playgroud)

要从同一项目中的另一个模块中删除:

delete project(':test').file('build/')
Run Code Online (Sandbox Code Playgroud)

如果我想删除模块下build.gradle中根项目中的文件夹怎么办?

android gradle build.gradle

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