I am using the typeface in my text view and it is all looking good. Now I want to set the seekbar which will help the user to adjust the text size under the text view.
I have just used the seekbar and played with it. this is how I am using my Seekbar to make the text larger
/// SeekBar Progress
sk.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int p=0;
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(p<30)
{
p=30;
sk.setProgress(p);
}
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
p=progress;
myTextView.setTextSize(p);
}
});
this is working and changing the size of text in the text view, But now there comes the problem :
Problem :
Problem is , the size is increasing and decreasing also when we take the seek bar to the left from its mid point. where as I want to set the minimum and maximum value. So to set the minimum and maximum I need to get the size of text inside the text view . and I have not found any method to get the textsize like for example myTextview.getTextSize() , there is no such method like it.
Let me tell you I am setting the size of the text view from the dimens file in the different values folder for supporting all the device and to make my text look good on tablets and small devices.
So now All I need to get is My text size inside the Text view . Please help me in getting the text size. thank you.
There is TextView.getTextSize(). You can also go TextView.getPaint().getTextSize().
try this
text_one.setText("your text");
text_one.measure(0, 0); //must call measure!
text_one.getMeasuredHeight(); //get height
text_one.getMeasuredWidth();
Do check that your myTextView is indeed TextView and not just View when you initialize it. e.g.
TextView myTextView = (TextView) findViewById(yourTextViewId);
I think the simplest answer is
myTextView.getTextSize();
Actually I was casting my value wrong. and Now it is solved. after doing this
float size = myTextView.getTextSize();
Related
I'm currently trying to retrieve the size of my button but it return wrong size. The text of my button is variable.
I retrieve the button width like that :
button.getWidth()
But it says 420px even if I set a larger text.
How can I get the correct size?
I have already tried to use addOnLayoutChangeListener, it worked but in te onlayoutchange function I could not update the UI.
override onWindowFocusChanged
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
int w=button.getWidth();
Log.d(TAG,w);
}
I have the following code in onCreate() Activity:
SeekBar vSeekbar = (SeekBar)findViewById(R.id.seekBar1);
final TextView tvText = (TextView) findViewById(R.id.textView);
//sets seekbar tab position from a randomly generated number...
//when the acitivty is first created I would like the SeekBar position to be set in the `textView`
tvText.setText(vSeekbar.getProgress()); //this is not showing anything...
//the onchangelistener works correctly...
vSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()
{
#Override
public void onStopTrackingTouch(SeekBar arg0)
{
}
#Override
public void onStartTrackingTouch(SeekBar arg0)
{
}
#Override
public void onProgressChanged(SeekBar arg0, int progress, boolean arg2)
{
tvText.setText(String.valueOf(progress)); //this works fine...
}
});
The seekBar1 position is set by a random number generated when the view is created so no way for me to know beforehand.
How can I get the seekBar1 position when the view is created and set it in the textView.
After random value set to seekbar call vSeekbar.getProgress() method. before you called then only you got zero value.
vSeekbar.setProgress(randomValue());
tvText.setText(vSeekbar.getProgress()+"");
You better limit your random values to the ProgressBar maximum value.
For example if your maximum value is 100 then use the following code: vSeekbar.setProgress(randomValue() % 100);
It will limit the random values to 0 to 99
I have a progressbar that i have defined for accepting the rating
RATINGbar = (SeekBar)findViewById(R.id.RATINGseekBarID); // make seekbar object
RATINGbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
RATINGtextProgress = (TextView)findViewById(R.id.RATINGtextViewProgressID);
RATINGtextProgress.setText("Rating:: "+progress);
seekBar.setMax(5);
}
});
This Bar accepts maximum of 5 number as i have defined !
when i select it and scroll horizontally, it accepts values as
1-2-3-4-5
How to make the progress bar take values like
1-1.5-2-2.5-3-3.5-4-4.5-5
what changes should i need to make here
How to make my progress bar accept values in interval of 0.5
Hope i am clear
How to make my progress bar accept values in interval of 0.5
Short answer:
You can't. ProgressBar takes only int values for actual and max progress and you can't change this behaviour. This how it's designated by OS.
Update: Look also at this thread.
You can't change ProgressBar intervals to float. Instead, try using RatingBar.
I have two questions:
How do I adjust the buttons in a table, like a normal calculator?
Whenever I click the 'equal' button the app is closing -Force
Close.
I think the problem comes from the int sum=0; whenever I use it at the equal place it gives the error.
code
use this code it may help
display.setText(sum+"");
because you have declared sum as int and setText property accepts CharSequence
For adjusting buttons, use TableLayout or RelativeLayout, where you can position buttons relatively to others.
Concerning second question, just change
display.setText(sum);
to
display.setText(String.valueOf(sum));
To make your calculator work at least a little bit change equal.setOnClickListener to this:
equal.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
display.setText(String.valueOf(counter+sum));
counter=0;
sum=0;
}
});
I have created the textview dynamically. My whole project is in white background so I made this textview background white. If I click one of the textview items it should take me to another activity. I got that output.
But my problem is I cant see Textview is clicked or not. I have done this through textview.setClickable(true). I can see if it is black background. can anyone help me please
Sorry I forgot to add, My textcolor is black
you have to implement onClickListener for that text field, for example:
yourTextField.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});