我想要android:可见性根据返回的布尔值在xml布局中解析。 像android:visibility =“card.isPrimary()?1:0”。
Android文档显示可见,不可见和不存在的是0,1,2。我的理解是真的/ 1会解析为隐形,而假/ 0会变为可见。
布局:
<LinearLayout>
<ImageView
android:visibility="@{ creditCard.isPrimary()}"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:src= "@drawable/creditcard" />
</LinearLayout>
答案 0 :(得分:1)
然后,isPrimary()应该返回相应的可见性值
NSString *token = [tokenData objectForKey:@"access_token"];
NSString *tokenType = [tokenData objectForKey:@"token_type"];
NSString *header = [NSString stringWithFormat:@"%@ %@", tokenType, token];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.spotify.com/v1/search?%@",trackId]];
[request setValue:header forHTTPHeaderField:@"Authorization"];
[request setURL:url];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (!error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
// JSON with song is here
}
}] resume];