I am making a contact app and I have added an image button. When user clicked on the image button, he/she would be directed to the calling application. When I run the code on the emulator, the image button does not work.
Below is my code:
public void addListenerOnButton() {
imageButton = (ImageButton) findViewById(R.id.imageButton1);
imageButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:12125551212"));
startActivity(intent);
}
});
}
The LogCat shows that eglSurfaceAttrib not implemented. Where did I get wrong?
Any help will be appreciated. Thanking you.
Related
I have two separate apps. the packages are as follows:
com.example.incrediblemachine.rnt
com.example.incrediblemachine.palpal
i would like to do the following:
when clicked on a button on the rnt app, i want the palpal app to open.
is there any way to do this?
Use getLaunchIntentForPackage method in your Button onClick() . Before that install com.example.incrediblemachine.palpal app in device /emulator.
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.example.incrediblemachine.palpal");
startActivity(launchIntent);
}
});
I have a problem when I logout using the Facebook API. Apart from the button to log in and out, I have another button that allows access to other activity, what happens is that when I logout I want to disappear the button that gives me access to the other activity and I can not do it, I have tried many combinations with all methods of the main activity and nothing works
Any suggestions?
Get a reference to the Facebook Login Button and set a click listener on it and when click is registered, logout using LoginManager instance and make all your logout procedure ( such as clearing stored access token, clearing cache, etc.) and then make visibility of the other button View.GONE
Eg:
LoginButton mBtnFbLogin = (LoginButton) findViewById(R.id.fb_login_button);
Button otherButton = (Button) findViewById(R.id.other_button)
Now set click listener on it.
mBtnFbLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LoginManager.getInstance().logOut();
// Make your logout procedure
...
otherButton.setVisibility(View.GONE);
}
});
Thank your for your answer, the solution works. Finally I do this:
#Override
protected void onResume() {
super.onResume();
AppEventsLogger.activateApp(this);
if (AccessToken.getCurrentAccessToken() != null && com.facebook.Profile.getCurrentProfile() != null) {
boton_volver.setVisibility(View.VISIBLE);
boton_volver.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent;
intent = new Intent(v.getContext(), EventosActivity.class);
startActivity(intent);
}
});
} else {
boton_volver.setVisibility(View.INVISIBLE);
}
}
I am making a log-in system on Android. And I want the register Button to be unclickable when it has been clicked. I am using this code:
final Button register = (Button) findViewById(R.id.register);
register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
register.setEnabled(false);
Intent register = new Intent(getApplicationContext(), register.class);
startActivity(register);
}
});
This is working great, but I want the Button to remain unclickable even when the application or phone has been restarted. Does anyone know a way to make the Button unclickable permanently even when the application has been shut down?
As I already said in the comments section something like this may work:
public class MyActivity extends Activity {
private static final String KEY_IS_BUTTON_CLICKABLE = "key_clickable";
#Override
public void onCreate(Bundle savedInstanceState) {
...
final Button register = (Button) findViewById(R.id.register);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
boolean isClickable = sharedPreferences.getBoolean(KEY_IS_BUTTON_CLICKABLE, true);
register.setEnabled(isClickable);
if(isClickable) {
register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
register.setEnabled(false);
PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
.putBoolean(KEY_IS_BUTTON_CLICKABLE, false);
Intent register = new Intent(getApplicationContext(), register.class);
startActivity(register);
}
});
}
}
...
}
In this case you could take a pessimistic approach and disable the button in the layout (by default) with android:clickable="false" and enable it in the condition where registration is required.
Hello every thing for change Button change image I found, was change image when you clicking on button like this
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ImageButton aButton = (ImageButton)v;
aButton.setImageResource(R.drawable.image1);
}
});
//I wanna change button image here
How can I change image source out of "on click" function?
Your question is confusing but to do what you want your code should be the following:
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
ImageButton aButton = (ImageButton)v;
aButton.setImageResource(R.drawable.image1);
}
});
imageButton.setImageResource(R.drawable.image2);
This will set your buttons image resource to image2 - but change to image1 when it is clicked.
i think you want selector means when you press button then its background changed and when we relieve then it will get previous image.
for this you will selector:
http://www.mkyong.com/android/android-imagebutton-selector-example/
i hope, it will help.
I assume that imageButton is global variable inside parent class
imageButton = (ImageButton) findViewById(R.id.imageButton);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
imageButton.setImageResource(R.drawable.image1);
}
});
imageButton = (ImageButton) findViewById(R.id.imageButton);
// This will change the Image Button to use image2
imageButton.setImageResource(R.drawable.image2);
imageButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
imageButton.setImageResource(R.drawable.image1);
}
});
However i must ask why you need to change imageButton to image2 in the code at the place that you asked? You can simply achieve this in xml.
I want to show a custom dialog and force the user to click on whether button one or two.
The problem is that users can use the back button AND if they click on the view that is shown in the background my dialog also disappears.
Why? And how could I prevent this?
final Main t = this;
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.prompt_input_access);
dialog.setTitle("Title");
Button cmdLoginAccount = (Button) dialog.findViewById(R.id.cmdLoginAccount);
Button cmdLoginBank = (Button) dialog.findViewById(R.id.cmdLoginBank);
cmdLoginAccount.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
loginToBank = true;
dialog.dismiss();
Intent intent = new Intent(t, UserMenu.class);
startActivity(intent);
}
});
cmdLoginBank.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
loginToBank = false;
dialog.dismiss();
Intent intent = new Intent(t, UserMenu.class);
startActivity(intent);
}
});
dialog.show();
You just need to use the setCanceledOnTouchOutside method :
dialog.setCanceledOnTouchOutside(false);