对于EditText控件来说可能需要用户输入提示,比如这个文本库是需要输入姓名的,可能 输入提示的内容为 “单击输入姓名”,使用Java代码,直接调用setHint(CharSequence hint) 即可,而对于layout xml布局文件而言,可以加入android:hint="单击输入姓名" 这行在你的 EditText 中即可。
输入提示颜色为灰色的,用户单击后自动清除,一般作用是告诉用户这个文本框需要输入的内容是什么。
http://marshal.easymorse.com/archives/2662
http://phenom.iteye.com/blog/655959
http://blog.csdn.net/Android_Tutor/archive/2010/08/19/5824581.aspx
http://mobile.csdn.net/n/20100909/279255.html iphone开源资源
http://blog.chinaunix.net/u2/86974/showart_2289102.html
http://www.blogjava.net/changcheng/archive/2010/03/04/314515.html
http://www.cnblogs.com/phinecos/archive/2009/08/28/1555980.html
http://www.zxhwolfe.com/archives/534
http://android.amberfog.com/?p=296
访问某些网页可能需要认证,比如JavaEye的Api。
如下方法可以做到访问这样的网页,本信息转自:
http://www.chrisumbel.com/article/basic_authentication_iphone_cocoa_touch
首先需要一个Base64类
@interface Base64 : NSObject { } @end static char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @implementation Base64 + (unsigned char *)encode:(NSData *) plainText { unsigned char *outputBuffer = malloc((((([plainText length] % 3) + [plainText length]) / 3) * 4) + 1); unsigned char *inputBuffer = (unsigned char *)[plainText bytes]; NSInteger i; NSInteger j = 0; int remain; for (i = 0; i < [plainText length]; i += 3){ remain = [plainText length] - i; outputBuffer[j++] = alphabet[(inputBuffer[i] & 0xFC) >> 2]; outputBuffer[j++] = alphabet[((inputBuffer[i] & 0x03) << 4) | ((remain > 1) ? ((inputBuffer[i+1] & 0xF0) >> 4) : 0)]; if (remain > 1){ outputBuffer[j++] = alphabet[((inputBuffer[i+1] & 0x0F) << 2) | ((remain > 2) ? ((inputBuffer [i+2] & 0xC0) >> 6) : 0)]; }else{ outputBuffer[j++] = '='; } if (remain > 2){ outputBuffer[j++] = alphabet[inputBuffer[i+2] & 0x3F]; }else{ outputBuffer[j++] = '='; } } outputBuffer[j] = '0'; return outputBuffer; } @end
实现:
NSURL *url = [NSURL URLWithString:@"http://api.iteye.com/api/auth/verify"]; NSString *userName = @"username"; NSString *password = @"password"; NSMutableString *loginString = (NSMutableString*)[@"" stringByAppendingFormat:@"%@:%@", userName, password]; char *encodedLoginData = [Base64 encode:[loginString dataUsingEncoding:NSUTF8StringEncoding]]; NSString *authHeader = [@"Basic " stringByAppendingFormat:@"%@", [NSString stringWithCString:encodedLoginData length:strlen(encodedLoginData)]]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 3]; [request addValue:authHeader forHTTPHeaderField:@"Authorization"]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSStringEncoding strEncode = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingUTF8); NSString *returnStr = [[NSString alloc] initWithData:returnData encoding:strEncode]; NSLog(@"%@", returnStr);
把username,password替换成真实的JavaEye用户信息。