i have build some simple app which contain one textview and two button
and at programmatic i have find there id and change textsize as button click as per below.
Button btn1,btn2;
TextView txtmain;
txtmain=(TextView)findViewById(R.id.textView1);
btn1=(Button)findViewById(R.id.button1);
btn2=(Button)findViewById(R.id.button2);
txtmain.setBackgroundColor(Color.YELLOW);
btn1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
txtmain.setTextSize(30);
}
});
btn2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
txtmain.setTextSize(100);
}
});
so the output is as below when i click btn2 textsize is 100 and when i select textview size is 30 but in android os 4.0.3 output is very different from other os.
button1 click output screen
button2 click output screen
Again button1 click mismatch output as per button1 clicked image
so please help me how to solved this problem this is one simple demo. is this any os related problem because apart from android os 4.0.3 it is run perfect.
see the following link.
https://code.google.com/p/android/issues/detail?id=17343
this is the android ice cream sandwich issue .
solve this issue add extra spacing character end of the text.
example:
final String DOUBLE_BYTE_WORDJOINER = "\u2060";
txtmain=(TextView)findViewById(R.id.textView1);
txtmain.setTextSize(TypedValue.COMPLEX_UNIT_SP ,30);
txtmain.append(DOUBLE_BYTE_WORDJOINER);
Related
I've set a button up to change the language from English to Welsh, only about 5 lines of English so just changing the text in each box manually with .setText
I also needed to change the text on the buttons, this works but once I change the language the other buttons fail to function.
The code below is what happens when the "English" button is pressed (same happens with the Welsh button is pressed..but in Welsh). Once pressed the calc, reset, calc2, and reset2 buttons stop doing the function they are set up to do...but they work before neither button is pressed.
Any ideas?
Thanks
english.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
quantity1.setText("Quantity");
total1.setText("Minimum");
Button calc = findViewById(R.id.buttoncalc);
calc.setOnClickListener(this);
calc.setText("Calculation");
Button reset = findViewById(R.id.buttonreset);
reset.setOnClickListener(this);
reset.setText("Reset");
Button calc2 = findViewById(R.id.buttoncalc2);
calc2.setOnClickListener(this);
calc2.setText("Calculation");
Button reset2 = findViewById(R.id.buttonreset2);
reset2.setOnClickListener(this);
reset2.setText("Reset");
multi_title.setText("Multi Calculator");
single_title.setText("Single Calculator");
}
});
this is the completely wrong approach to the problem ...
because the framework perfectly supports this out of the box, without messing around.
Android Studio even features a translation editor, where one can translate side-by-side.
see the documentation and also localization.
calc.setOnClickListener(this);
this keyword here reference to English's click listener that's why your basic functionality is not working.
Try to set all clicklistener outside english click listener's scope.
And your code will work fine.
Button calc = findViewById(R.id.buttoncalc);
Button reset = findViewById(R.id.buttonreset);
Button calc2 = findViewById(R.id.buttoncalc2);
Button reset2 = findViewById(R.id.buttonreset2);
setClicks();
english.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
quantity1.setText("Quantity");
total1.setText("Minimum");
calc.setText("Calculation");
reset.setText("Reset");
calc2.setText("Calculation");
reset2.setText("Reset");
multi_title.setText("Multi Calculator");
single_title.setText("Single Calculator");
}
});
private void setClicks() {
calc.setOnClickListener(this);
reset.setOnClickListener(this);
calc2.setOnClickListener(this);
reset2.setOnClickListener(this);
}
Please try this and check it again
In my android app, I have a Play button. After I manually clicked the button, everything works fine. but when I use uiautomator to trigger the button click, nothing happend. After debugging, I am pretty sure it is the string comparison step (labeled stuck here) that causes the failure. Very confused why it behaves differently. I do see the button get clicked in both ways (with button color change). If I use button.getText().toString(), both worked. BTW, button.getText() returns CharSequence, not String object.
I defined my string values in res/values/strings.xml as
<string name="play">Play</string>
The java code:
private final static String PLAY = "Play";
//some code in between
Button playButton = new Button(this);
playButton.setText(R.string.play);
playButton.setTextSize(BUTTON_FONT_SIZE);
playButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Button b = (Button) v;
if (b.getText().equals(PLAY)) { //stuck here.
startPlay();
} else {
stopPlay();
}
}
});
Could you please share how you tried to click the button using UiAutomator. Below code should work
UiObject buttonToClick = new UiObject(new UiSelector ().text(Play).className("android.widget.Button")); buttonToClick.clickAndWaitForNewWindow();
i'm using setColorFilter to color some button... the code is this:
final Button falso = (Button) findViewById(R.id.falso);
final Button vero = (Button) findViewById(R.id.vero);
vero.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
vero.getBackground().setColorFilter(new LightingColorFilter(0x00000000, 0x00FF0FF));
falso.getBackground().clearColorFilter();
esame.set("V");
}
});
falso.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
falso.getBackground().setColorFilter(new LightingColorFilter(0x00000000, 0x00FF0FF));
vero.getBackground().clearColorFilter();
esame.set("F");
}
});
when i click the button "vero" i want reset the colour of "falso" and viceversa.
i tried this code on android ics and all work good, but when i tried it on android 2.3 i have a bad surprise.
when i click the button the colour don't reset and i don't understand why.
i find the solution:
use button.invalidate();
after i clear background
Setting the ColorFilter to 0 will do thee job by clearing the filter.
vero.setInt(vero.getBackground(), "setColorFilter", 0);
I am developing an quiz based application. I wanted to know like, how can we change the questions and its options without changing the text view where the question will appear and the layout when the user clicks next button i want the same text view and layout only question and its options should change.I am new to the android so can anyone help me out ..
you can change the text of texview on click of next button like this
TextView textView=(TextView) findViewById(R.id.textview1);
Button next=(Button) findViewById(R.id.nextbutton);
next.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
textView.setText("Your Text");
}
});
Let's pretend this was my Java Class...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ScreentwoGameButton = (Button) findViewById(R.id.screentwo);
ScreentwoGameButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent ScreentwoGameIntent = new Intent(Main.this, Screentwo.class);
startActivity(StartGameIntent);
}
});
How do i use this code below but the right way like.
So let's put an example if I click screentwo button the screentwo.xml will show and it will allow me to click inside if any buttons are available. Instead just stare what's in the layout.
I don't want to use the Activity to activity cause the whole point is i'm trying to avoid the flashing looking feel going to another java class.
If you look at the moron test game on Android it says example: press the blue button then red and then green, so if u press the blue button the screen will remain and not flash at all but the image of the blue button will disappear and I'm allowed to click the red and then green.
Hope that helped.
Thanks
Wahid
Button ScreentwoButton = (Button) findViewById(R.id.screentwo);
ScreentwoButton.setOnClickListener(new OnClickListener() {
private Uri Uri;
#Override
public void onClick(View v) {
setContentView(R.layout.Screentwo);
Uri uri=Uri;
Intent i=new Intent(Intent.ACTION_VIEW, uri);
mSoundManager.playSound(1);
}
});
try to use:
setContentView(R.layout.next layout); in your button click.
You could use the viewflipper class and add the different layouts as childs to the viewflipper
and set the active child. Using setcontentView will be trouble some when you use findViewById for a old layout. As findViewById will look in the layout that is specified by setContentView