我在android中有3个搜索栏。
我希望每次用户选择这些搜索栏时都显示texview的值并相应地修改它们。我已将setText函数放在onStopTrackingTouch方法中。但它显示的全部是0。 有人可以帮助。 感谢。
我的代码:
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.TextView;
import app.minimize.com.seek_bar_compat.SeekBarCompat;
public class BudgetActivity extends AppCompatActivity {
public TextView seekbarvalue;
int groceryvalue,restaurantvalue,enterntainmnetvalue,totalvalueset,totalbudget=1000;
boolean isGrocerySet,isEntertainmnetSet,isRestaurantSet;
SeekBarCompat groceryseekBarCompat,entertainmentseekBarCompat,restaurantseekbarCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_budget);
// CrystalSeekbar groceryseekBarCompat = (CrystalSeekbar) findViewById(R.id.grocerySeekBar);
groceryseekBarCompat = (SeekBarCompat) findViewById(R.id.groceryseekbar);
groceryseekBarCompat.setThumbColor(Color.MAGENTA);
groceryseekBarCompat.setProgressColor(Color.LTGRAY);
groceryseekBarCompat.setProgressBackgroundColor(Color.GREEN);
groceryseekBarCompat.setThumbAlpha(128);
groceryseekBarCompat.setMax(totalbudget);
entertainmentseekBarCompat = (SeekBarCompat) findViewById(R.id.entertainmentseekbar);
entertainmentseekBarCompat.setThumbColor(Color.RED);
entertainmentseekBarCompat.setProgressColor(Color.MAGENTA);
entertainmentseekBarCompat.setProgressBackgroundColor(Color.BLUE);
entertainmentseekBarCompat.setThumbAlpha(128);
entertainmentseekBarCompat.setMax(totalbudget);
restaurantseekbarCompat = (SeekBarCompat) findViewById(R.id.restaurantseekbar);
restaurantseekbarCompat.setThumbColor(Color.YELLOW);
restaurantseekbarCompat.setProgressColor(Color.CYAN);
restaurantseekbarCompat.setProgressBackgroundColor(Color.GREEN);
restaurantseekbarCompat.setThumbAlpha(128);
restaurantseekbarCompat.setMax(totalbudget);
seekbarvalue = (TextView) findViewById(R.id.seekbarvalue) ;
/**
* Listener for grocery seekbar
*/
groceryseekBarCompat.setOnSeekBarChangeListener(new SeekBarCompat.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
seekbarvalue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Log.d("Grocery on start" ,"clicked");
totalvalueset = totalvalueset - seekBar.getProgress();
Log.d("On start totalvalueset" ,String.valueOf(totalvalueset));
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
groceryvalue = seekBar.getProgress();
Log.d("Seekbar progress" ,String.valueOf(seekBar.getProgress()));
// seekbarvalue.setText(String.valueOf(seekBar.getProgress()));
if(totalvalueset <=1000) {
totalvalueset += groceryvalue;
}
Log.d("Grocery on stop" ,String.valueOf(groceryvalue));
Log.d("totalvalueset++++++" ,String.valueOf(totalvalueset));
isGrocerySet = true;
isEntertainmnetSet = false;
isRestaurantSet = false;
setDynamicLimit();
}
});
/**
* Listener for the enterntainment seekbar
*/
entertainmentseekBarCompat.setOnSeekBarChangeListener(new SeekBarCompat.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
seekbarvalue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Log.d("Enterntainment on start" ,"clicked");
totalvalueset = totalvalueset - seekBar.getProgress();
Log.d("On start totalvalueset" ,String.valueOf(totalvalueset));
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
enterntainmnetvalue = seekBar.getProgress();
if(totalvalueset <=1000) {
totalvalueset += enterntainmnetvalue;
}
Log.d("Entertainment on stop" ,String.valueOf(enterntainmnetvalue));
Log.d("totalvalueset+++++" ,String.valueOf(totalvalueset));
seekbarvalue.setText(String.valueOf(enterntainmnetvalue));
isEntertainmnetSet = true;
isGrocerySet = false;
isRestaurantSet = false;
setDynamicLimit();
}
});
/**
* Listener for the restaurant seekbar
*/
restaurantseekbarCompat.setOnSeekBarChangeListener(new SeekBarCompat.OnSeekBarChangeListener(){
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
restaurantvalue = progress;
seekbarvalue.setText(String.valueOf(progress));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
Log.d("Restaurant on start" ,"clicked");
totalvalueset = totalvalueset - seekBar.getProgress();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
restaurantvalue = seekBar.getProgress();
seekbarvalue.setText(String.valueOf(restaurantvalue));
if(totalvalueset <=1000) {
totalvalueset+=restaurantvalue;
}
Log.d("Restaurant on stop" ,String.valueOf(restaurantvalue));
Log.d("totalvalueset++" ,String.valueOf(totalvalueset));
isRestaurantSet = true;
isGrocerySet = false;
isEntertainmnetSet = false;
setDynamicLimit();
}
});
}
private void setDynamicLimit() {
Log.d("setting dynamic limit" , String.valueOf(totalbudget-totalvalueset));
if(!isEntertainmnetSet) entertainmentseekBarCompat.setMax(totalbudget-totalvalueset);
if(!isRestaurantSet) restaurantseekbarCompat.setMax(totalbudget-totalvalueset);
if(!isGrocerySet) groceryseekBarCompat.setMax(totalbudget-totalvalueset);
}
}
答案 0 :(得分:0)
应该{{1}}传递TextView,如下所示:
yourTextViewName.setText(“”+ progress +“”);
希望这有帮助。帮助。