我有一系列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) 这是我的ArrayAdapter.我希望通过遵循ViewHolder模式来提高效率:
但我不确定如何做到这一点.
更新: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) 我收到警告:
Attribute minSdkVersion (3) is lower than the project target API level (8)
Run Code Online (Sandbox Code Playgroud)
这将如何影响我的应用程序?
我设计了一个带有工具栏的视图,该工具栏在Interface Builder中以模态方式显示.我有一个位于左侧的UIBarButtonItem,我希望它出现在工具栏的右侧.我如何在IB中或通过代码执行此操作?
iphone cocoa-touch objective-c interface-builder iphone-sdk-3.0
当我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) 我们假设我有字符串
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)
但两者都留下了空间.
我要求用户通过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) 我试图将自己的自定义对象传递到一个包中:
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) 我有一个需要保存的JSON数组.我正在考虑将其序列化,但是将它作为字符串保存在SharedPreferences中然后在我需要读取它时重建它会更好吗?
如果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) android ×6
cocoa-touch ×4
iphone ×4
java ×4
objective-c ×4
cocoa ×2
listview ×2
bundle ×1
colors ×1
dialog ×1
json ×1
listviewitem ×1
nsdictionary ×1
nsstring ×1
object ×1
variables ×1
xml ×1