Android onTouchEvent and TouchListener 的执行流程

public boolean dispatchTouchEvent(MotionEvent event) {
	if (mInputEventConsistencyVerifier != null) {
		mInputEventConsistencyVerifier.onTouchEvent(event, 0);
	}

	if (onFilterTouchEventForSecurity(event)) {
		// noinspection SimplifiableIfStatement
		ListenerInfo li = mListenerInfo;
		if (li != null && li.mOnTouchListener != null
				&& (mViewFlags & ENABLED_MASK) == ENABLED
				&& li.mOnTouchListener.onTouch(this, event)) {
			return true;
		}

		if (onTouchEvent(event)) {
			return true;
		}
	}

	if (mInputEventConsistencyVerifier != null) {
		mInputEventConsistencyVerifier.onUnhandledEvent(event, 0);
	}
		return false;
}

所有,如果在注册的TouchListener中返回了true, 那么你自定义View中的onTouchEvent()方法就执行不到咯。ref: frameworks/base/core/java/android/view/View.java

Android Wear 调试方法

通过USB

adb -d forward tcp:5601 tcp:5601

通过蓝牙

  1. 在手机端打开Android Wear应用

  2. 点击界面右上的菜单并选择设置(Settings)

  3. 开启“通过蓝牙调试”(Debugging over Bluetooth)。你可以看到设备连接状态:
    Host: disconnected Target: connected
    
  4. 手机用usb连接电脑,并执行adb命令:
    adb forward tcp:4444 localabstract:/adb-hub
    adb connect localhost:4444
    

    你就可以看到刚才的连接状态就变成了:

Host: connected Target: connected

Java DOM 解析 GBK 编码的 XML

final String XMLString = ""
                    + ""
                    + "张三"
                    + "";

private static final DocumentBuilderFactory sDocBuilderFactory = 	     					  DocumentBuilderFactory.newInstance();
DocumentBuilder builder = sDocBuilderFactory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(xmlString.getBytes("GBK"));
Reader reader = new InputStreamReader(is, "GBK");
InputSource source = new InputSource(reader);
Document doc = builder.parse(source);

Mac Eclipse 中文乱码

MacEclipse中文乱码

iOS PickerView 联动

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"provinces_cities" ofType:@"plist"];
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
    self.pickerData = dict;
    self.pickerProvincesData = [self.pickerData allKeys];
    
    NSString *selectedProvincesData = [self.pickerProvincesData objectAtIndex:0];
    self.pickerCitiesData = [self.pickerData objectForKey:selectedProvincesData];
    
    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;
}

- (NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    if (component == 0) {
        return [self.pickerProvincesData objectAtIndex:row];
    } else {
        return [self.pickerCitiesData objectAtIndex:row];
    }
}

- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == 0) {
        NSString *selectedProvince = [self.pickerProvincesData objectAtIndex:row];
        NSArray *array = [self.pickerData objectForKey:selectedProvince];
        self.pickerCitiesData = array;
        [self.pickerView reloadComponent:1];
    }
}


- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 2;
}

- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    
    if (component == 0) {
        return [self.pickerProvincesData count];
    } else {
        return [self.pickerCitiesData count];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onClick:(UIButton *)sender {
    NSInteger row1 = [self.pickerView selectedRowInComponent:0];
    NSInteger row2 = [self.pickerView selectedRowInComponent:1];
    NSString *selected1 = [self.pickerProvincesData objectAtIndex:row1];
    NSString *selected2 = [self.pickerCitiesData objectAtIndex:row2];
    NSString *title = [[NSString alloc] initWithFormat:@"%@, %@市", selected1, selected2];
    self.label.text = title;
}
@end