onClick() doesn't work on JellyBean - android

How i said in the title onClick event doesn't work with JellyBean devices.
Here there is the code
((Button)view.findViewById(R.id.more_questions)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LinearLayout linearLayout= (LinearLayout)view.findViewById(R.id.linear);
EditText radioButton= new EditText(getContext());
radioButton.setText("Inserisci la nuova domanda");
radioButton.setSelectAllOnFocus(true);
domande.add(radioButton);
linearLayout.addView(radioButton);
}
});
Can someone fix my problem?? Becouse with the higher api's Versions there isn't this problem

Related

Android can not remove button

I am trying to remove a button when the button itself is tapped, I am trying the following:
View.OnClickListener getOnClickDoSomething(final Button button) {
return new View.OnClickListener() {
public void onClick(View v) {
tagsView.removeView(button);
}
};
}
This code is working, but when I add the following line of code:
editText.setText(button.getText());
The code stops working and the button does not get removed. I add it like so:
View.OnClickListener getOnClickDoSomething(final Button button) {
return new View.OnClickListener() {
public void onClick(View v) {
editText.setText(button.getText());
tagsView.removeView(button);
}
};
}
What is the problem here?
use this in your OnClick method
button.setVisibility(view.GONE);
Your code will look like this
View.OnClickListener getOnClickDoSomething(final Button button) {
return new View.OnClickListener() {
public void onClick(View v) {
editText.setText(button.getText());
button.setVisibility(view.GONE);
}
};
}
Or Try this
Button mybtn = (Button)findViewById(R.id.mybtn_id);
mybtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
mybtn.setVisibility(view.GONE); // or (view.INVISIBLE)
}
});
Depending on what you're trying to achieve, something like deejay proposed would work just fine. If want the button to hide, call button.setVisibility(View.INVISIBLE). However, if you are trying to dismiss it completely from the view hierarchy, call button.setVisibility(View.GONE).
just set button visibility to false
Obviously button.setVisibility(View.GONE) comes to mind but if it doesn't work you should look one level above for the source of the bug. Maybe you don't set OnClickListener you created to the button and hence nothing happens?

setTextDirection Programatically in api level 17

We are trying to set textDirection "rtl" programatically.
But, when we set it to "ltr" then on button click changing textDirection to "rtl" is not working.
Here is my code :
edtUSername.setTextDirection(View.TEXT_DIRECTION_LTR);
btnSubmit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
edtUSername.setTextDirection(View.TEXT_DIRECTION_RTL);
}
});
And this is not working only in api level 17.

how to use zoom button in a view android

I've always wanted to create an Android activity which uses zoombutton not the zoomcontroller in a view. But I don't know how to get started. I appreciate any help you would give me. If you could give me some piece of code to get started. Thanks
I don't really understand what you actually want to zoom, just want to give you the idea of Zooming a text for a TextView here the code for it.
ImageView increaseTextBtn = (ImageView)findViewById(R.id.increaseTextBtn);
final TextView txtTitle = (TextView) findViewById(R.id.txt_desc);
increaseTextBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
txtTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX,(txtTitle.getTextSize()+1f));
}
});
ImageView decreaseTextBtn = (ImageView)findViewById(R.id.decreaseTextBtn);
decreaseTextBtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
txtTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX,(txtTitle.getTextSize()-1f));
}
});
in this code there are two buttons (increaseTextBtn , decreaseTextBtn ) to adjust the zoom level of TextView
Update
For image view you can find an examle here

clearColorFilter() don't work on android 2.3

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);

Button in slidingdrawer!

I'm having a button in a sliding drawer in a Android Application. The problem is it does not seem to react to any clicks as normal buttons do.
I'm guessing the problem is that it's a different view than buttons on the normal view.
If I implement a button the normal way like this
myAgenda = (Button)findViewById(R.id.BtnMyAgenda);
myAgenda.setOnClickListener(this);
public void onClick(View v) {
switch(v.getId()){
case R.id.BtnMyAgenda:
test.setAnimation(leftLeft);
test.startAnimation(leftLeft);
break;
}
I'm guessing there is something wrong with the above code since the button is in a SlidingDrawer and not in the "normal" view.
Any ideas how to fix the problem?
Here is the code
Register with event listner like below code
button.setOnClickListener(clickButtonListener);
and create this listner for button
private OnClickListener clickButtonListener= new OnClickListener()
{
#Override
public void onClick(View v)
{
if(v == button)
{
}
}
}
I actually found the solution to the problem, I simply created a new view.onclicklistener specific to that button.
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
}
});

Categories

Resources