Skip to main content

Featured

Android studio “SDK tools directory is missing”

Following 2 possible solutions will resolve this problem :  Solution1 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:" Delete your  ~/.Android*  folders (losing all of your settings :/). Run Android Studio. It will show you a welcome wizard where it tries to download the SDK again (and fails due to my rubbish internet). Click the X on the wizard window. That will enable you to get to the normal welcome dialog. Go to Settings->Project Defaults->Project Structure and change the Android SDK location to the correct one. Solution 2 : To fix the problem, it was required that I list the path to my corporate PAC file by using  Configure -> "Appearance and Behavior" -> System Settings -> HTTP Proxy . I selected "Automatic proxy configuration url:&quo

code to trigger menu after button click in Android


You can open the menu by using a Button with the following code
Button button = (Button)findViewById(R.id.my_bytton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
    openOptionsMenu();
}
});
Here is the onCreateOptionsMenu method :-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_1, menu);
return true;
}
And to handle the click event, use
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.new_menu:
    // do part 1
    return true;
case R.id.help_menu:
    // do part 2
    return true;
default:
    return super.onOptionsItemSelected(item);
}
}

Comments