下面的函数从共享偏好,权重和高度中获取两个值,我使用它们来计算BMI,当我打印值的内容时,我得到我在sharedprefs中输入的值(这很好)但是当我运行时对它们进行除法运算,结果总是得到0 ..错误在哪里?
public int computeBMI(){
SharedPreferences customSharedPreference = getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);
String Height = customSharedPreference.getString("heightpref", "");
String Weight = customSharedPreference.getString("weightpref", "");
int weight = Integer.parseInt(Weight);
int height = Integer.parseInt(Height);
Toast.makeText(CalculationsActivity.this, Height+" "+ Weight , Toast.LENGTH_LONG).show();
int bmi = weight/(height*height);
return bmi;
}
Run Code Online (Sandbox Code Playgroud) 我有以下材料自定义 sass 文件:
@import '../node_modules/@angular/material/theming';
@include mat-core();
$app-primary: mat-palette($mat-red, 700, 800);
$app-accent: mat-palette($mat-red, 700, 800);
$app-warn: mat-palette($mat-red, 700, 800);
$app-theme: mat-light-theme($app-primary, $app-accent, $app-warn);
$app-input-primary: mat-palette($mat-red, 100, 200);
$app-input-accent: mat-palette($mat-red, 100, 200);
$app-input: mat-light-theme($app-input-primary, $app-input-accent);
@include mat-core-theme($app-theme);
@include mat-checkbox-theme($app-theme);
@include mat-radio-theme($app-theme);
@include mat-input-theme($app-theme);
Run Code Online (Sandbox Code Playgroud)
样式正确应用于复选框和单选框,但不适用于输入字段。
这是我定义输入字段的方式:
<md-form-field>
<input mdInput placeholder="Card holder name">
</md-form-field>
Run Code Online (Sandbox Code Playgroud)
如果我使用单行更改细分包含,则@include angular-material-theme($app-theme);红色样式适用于输入,但我的想法是为输入字段使用不同的调色板。
我正在使用我的服务中定义的虚拟数据创建一个应用程序.
在一个组件中,我有以下删除产品的功能:
removeItem(productId: string) {
this.cartService.removeItem(productId);
}
Run Code Online (Sandbox Code Playgroud)
和服务如下:
removeItem(productId: string) {
const itemIndex = this.cart.products.findIndex(el => el.id === productId);
if (itemIndex > -1) {
this.cart.products.splice(itemIndex, 1);
return Observable.of(this.cart)
.subscribe((cartResponse: Cart) => {
this.store.dispatch({ type: CART_UPDATE, payload: cartResponse });
});
}
}
Run Code Online (Sandbox Code Playgroud)
(this.cart是我在服务中硬编码的数据).
我的减速机看起来像:
export const cartReducer = (state: Cart = {} as Cart, {type, payload}) => {
switch (type) {
case CART_UPDATE:
// update categories state
return payload;
default:
return state;
}
};
Run Code Online (Sandbox Code Playgroud)
然后我订购了一个组件中的购物车,如:
ngOnInit() {
this.store.select('cart').subscribe((cart: Cart) => { …Run Code Online (Sandbox Code Playgroud) 如何将 XML 代码中的元素包装在像框一样的视图中?这意味着我希望它们看起来像是被分组在某个带有边框的盒子中。
<Button
android:id="@+id/carbgraph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="230dp"
android:layout_y="378dp"
android:text="Button" />
<ProgressBar
android:id="@+id/progressBarforcals"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_x="15dp"
android:layout_y="346dp" />
<TextView
android:id="@+id/calsinmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="16dp"
android:layout_y="320dp"
android:text="TextView" />
Run Code Online (Sandbox Code Playgroud) 我现在遇到了一点麻烦。我基于 *ngSwitch 在用户个人资料中显示帖子:
<div [ngSwitch]="iconsMediaSegment">
<div *ngSwitchCase="'grid'">
<ion-grid>
<ion-row>
<ion-col *ngFor="let post of posts$ | async" col-4 class="col-image">
<img [src]='post.image'>
</ion-col>
</ion-row>
</ion-grid>
</div>
<div *ngSwitchCase="'list'">
<page-feed-item class="post-list" *ngFor="let post of posts$ | async" [feed]="post" ></page-feed-item>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,当它单独存在时,效果非常好,我可以在两个部分之间切换,没有任何问题。但我还想在视图的早期部分保留异步数据的计数器,如下所示:
<ion-col>
<p>Posts</p>
<span *ngIf="posts$">{{ (posts$ | async)?.length }}</span>
</ion-col>
Run Code Online (Sandbox Code Playgroud)
现在,当页面首次加载时,第一个部分(网格)具有帖子图像,{{ (posts$ | async)?.length }} 具有帖子数量,我们处于一个完美的世界中。但是,当我尝试切换到其他段(列表)时,问题就出现了,帖子从网格段和列表段中完全消失。
现在我知道对此的一个简单解决方法是添加一个新的可观察量,它是 posts$ 的精确副本,但只需将其命名为 postsCount$ 之类的名称,然后异步该长度,但我试图理解为什么原始方法不起作用,在没有冗余代码的情况下我还能做些什么来修复它。