我已经编写了这段代码。我想在文本视图中总结两个搜索栏的进度值。我已经尝试了几次,但是没有用。我想将两个值都放在一个变量中。在哪里可以使用百分比等变量。
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main); seekBar1=(SeekBar)findViewById(R.id.moveOnSeekBar1); seekBar2=(SeekBar)findViewById(R.id.moveOnSeekBar2); screenView1=(TextView)findViewById(R.id.screenView1); screenView2=(TextView)findViewById(R.id.screenView2); screenViewTotal=(TextView)findViewById(R.id.screenViewTotal);
final int total;
total=progress1Value+progress2Value;
seekBar1.setMax(20); seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar p1, int progress1, boolean p3)
{ screenView1.setText(Integer.toString(progress1));
progress1Value=progress1; screenViewTotal.setText(String.valueOf(total));
}
@Override
public void onStartTrackingTouch(SeekBar p1)
{
}
@Override
public void onStopTrackingTouch(SeekBar p1)
{
// TODO: Implement this method
}
});
seekBar2.setMax(20); seekBar2.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar p1, int progress2, boolean p3)
{ screenView2.setText(Integer.toString(progress2));
progress1Value=progress2; screenViewTotal.setText(String.valueOf(total));
}
@Override
public void onStartTrackingTouch(SeekBar p1)
{
}
@Override
public void onStopTrackingTouch(SeekBar p1)
{
// TODO: Implement this method
}
});
}
答案 0 :(得分:0)
我已经采用了您的代码并对其进行了修改。创建两个字段const together = ['bar', 'baz', 'buzz'];
const validate = obj => {
if (!obj.foo) return false;
const missingProps = together.filter(prop => !(prop in obj));
return (missingProps.length === 0 || missingProps.length === together.length)
? true
: 'missing ' + missingProps.join(', ');
};
console.log(validate({
foo: {},
bar: {},
baz: {}
}));
console.log(validate({
foo: {},
bar: {},
baz: {},
buzz: {}
}));
和progress1
。然后,当用户与搜索栏交互时,更新正确的值。然后致电progress2
,它将计算您的总数,以便您可以使用它来显示信息。
updateTotal()