小编She*_*lam的帖子

如何获得NSDictionary中的第一个元素?

我有一系列NSDictionaries.如何拉出字典中的第一个元素?

   NSArray *messages = [[results objectForKey:@"messages"] valueForKey:@"message"];         
    for (NSDictionary *message in messages)
    {
        STObject *mySTObject = [[STObject alloc] init];
        mySTObject.stID = [message valueForKey:@"id"];      
        stID = mySTObject.stID;
    }
Run Code Online (Sandbox Code Playgroud)

iphone cocoa cocoa-touch objective-c nsdictionary

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

如何使ArrayAdapter遵循ViewHolder模式?

这是我的ArrayAdapter.我希望通过遵循ViewHolder模式来提高效率:

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

但我不确定如何做到这一点.

更新:ViewHolder模式

private class QuoteAdapter extends ArrayAdapter<Quote> {

    private ArrayList<Quote> items;
    // used to keep selected position in ListView
    private int selectedPos = -1; // init value for not-selected

    public QuoteAdapter(Context context, int textViewResourceId, ArrayList<Quote> items) {
        super(context, textViewResourceId, items);
        this.items = items;
    }

    public void setSelectedPosition(int pos) {
        selectedPos = pos;
        // inform the view of this change
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        ViewHolder holder; // …
Run Code Online (Sandbox Code Playgroud)

java android listview android-arrayadapter

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

如果minSdkVersion低于targetSdkVersion会发生什么?

我收到警告:

Attribute minSdkVersion (3) is lower than the project target API level (8)
Run Code Online (Sandbox Code Playgroud)

这将如何影响我的应用程序?

xml android android-manifest

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

如何将UIBarButtonItem放在UIToolbar的右侧?

我设计了一个带有工具栏的视图,该工具栏在Interface Builder中以模态方式显示.我有一个位于左侧的UIBarButtonItem,我希望它出现在工具栏的右侧.我如何在IB中或通过代码执行此操作?

iphone cocoa-touch objective-c interface-builder iphone-sdk-3.0

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

如何为TextView定义ColorStateList?

当我ListViewItem突出显示时,我希望文本变为白色.我怎么定义这个?

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_focused="true" android:color="@color/testcolor1"/>
   <item android:state_pressed="true" android:state_enabled="false" android:color="@color/testcolor2" />
   <item android:state_enabled="false" android:color="@color/testcolor3" />
   <item android:color="@color/testcolor5"/>
 </selector>
Run Code Online (Sandbox Code Playgroud)

android listview colors listviewitem

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

如何在不插入空格的情况下替换NSString中的字符?

我们假设我有字符串

NSString* myString  = @"Hello,";
Run Code Online (Sandbox Code Playgroud)

如何在不留空格的情况下删除逗号?我试过了:

NSString* newString = [myString stringByReplacingOccurrencesOfString:@"," withString:@""];
Run Code Online (Sandbox Code Playgroud)

NSString* newString = [myString stringByTrimmingCharactersInSet:[NSCharacterSet punctuationCharacterSet]];
Run Code Online (Sandbox Code Playgroud)

但两者都留下了空间.

iphone cocoa cocoa-touch objective-c nsstring

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

如何在Dialog和Activity之间传递值?

我要求用户通过Dialog输入:

package com.android.cancertrials;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class CustomDialog extends Dialog  {


    private String name;
//    private ReadyListener readyListener;
     public static EditText etName;
     public String zip;

    public CustomDialog(Context context, String name) {
        super(context);
        this.name = name;
//        this.readyListener = readyListener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mycustomdialog);
        setTitle("Enter the Zip Code ");
        Button buttonOK = (Button) findViewById(R.id.ok);
        buttonOK.setOnClickListener(new OKListener());
        etName = (EditText) findViewById(R.id.EditZip);
    }

    private class OKListener implements android.view.View.OnClickListener …
Run Code Online (Sandbox Code Playgroud)

java variables android dialog

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

如何在Bundle中传递自定义对象?

我试图将自己的自定义对象传递到一个包中:

Bundle b = new Bundle();
                STMessage message = (STMessage)a.getAdapter().getItem(position);
                b.putObject("message",message);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

The method putObject(String, Object) is undefined for the type Bundle
Run Code Online (Sandbox Code Playgroud)

java android bundle object android-intent

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

可以在SharedPreferences中保存JSON数组吗?

我有一个需要保存的JSON数组.我正在考虑将其序列化,但是将它作为字符串保存在SharedPreferences中然后在我需要读取它时重建它会更好吗?

java serialization android json sharedpreferences

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

如何以UILabel缩小字体大小制作文本

如果UILabel包含太多文本,我如何设置我的标签以缩小字体大小?

以下是我设置UILabel的方法:

     descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 30, 130, 150)];
    [descriptionLabel setFont:[Utils getSystemFontWithSize:14]];
    [descriptionLabel setBackgroundColor:[UIColor clearColor]];
    [descriptionLabel setTextColor:[UIColor whiteColor]];
    descriptionLabel.numberOfLines = 1;
    [self addSubview:descriptionLabel];
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c interface-builder

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