We moved. Please visit this link for this post.
Sometimes you need to run some Activity, do some operation there and return some value to parent Activity. For this situation Android has possibility to run Activity for result. Read more…
We moved. Please visit this link for this post.
I found that there is no logcat console in android plugins for NetBeans and IDEA 8.
But when you develop application you need to see exceptions or see simple log.
I am going to show how easy is to see all these things in system console.
At first you should have installed Android SDK.
At second type in your console:
adb logcat
Note: emulator instance should be working.
We moved. Please visit this link for this post.
Context menu in Android is similar to context menu in any others OS.
In Microsoft Windows or in any Linux distr you click right mouse key and see context menu. The same is in Android, but you press and hold your view which has context menu. Read more…
We moved. Please visit this link for this post.
There is a way to add shortcut to your menu item.
I am going to show how it can be done.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, NEW_MENU_ITEM, 0, "New").setAlphabeticShortcut('N');
...
return super.onCreateOptionsMenu(menu);
}
As you see it is very easy.
How you can test it? Run your code with this snippet, click Menu button and after click “N”.
We moved. Please visit this link for this post.
There is a good practice to add icons to the menu items.
I am going to show code snippet which add icon to the menu item:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, ADD_MENU_ITEM, 0, "Add").setIcon(android.R.drawable.ic_menu_add);
return super.onCreateOptionsMenu(menu);
}
This code adds icon add to the menu item ADD_MENU_ITEM.
As you see this is simple operation.
We moved. Please visit this link for this post.
I found way to get formatted string from strings.xml.
I am going to show how I did it. Please refer to getString method.
strings.xml
<string name="text">My name is %s. I work at FaYna Soft Labs %d months.</string>
Activity
getResources().getString(R.string.text, "Oleg Mazurashu", 7)
Example:
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
* Activity which shows how to use formatted string from strings.xml
*
* @author FaYna Soft Labs
*/
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.textId);
tv.setText(getResources().getString(R.string.text, "Oleg Mazurashu", 7));
}
}
I like this approach.
We moved. Please visit this link for this post.
Submenu is a another way to group your menu items.
I am going to show how to create, add items and handle items selection. Read more…
We moved. Please visit this
link for this post.
Sometimes need to group your Options menu items.
Group is very useful when you need to work (remove, disable or hide) with several menu items.
I am going to show example about how to remove, disable/enable and hide/show group of menu items.
Read more…
We moved. Please visit this link for this post.
There are 2 approaches:
- Delete widget from emulator/device
- Delete widget from Home screen
I will explain second, how to delete widget from Home screen.
It will not the code snippet, it will use case.
There are 2 steps:
- Tap widget and hold your finger down. You will notice that the “slider” that normally brings up all of your installed programs turns into a “Trash can”.
- Drag the widget to that “Trash can”. Both the widget and the “Trash can” will turn red. At this point, let go of the widget (release your finger). That will “drop” it in the trash.
Note: this does not actually uninstall the widget. It just removes it from your Home screen.
That’s all. The widget has been removed from your Home screen.
We moved. Please visit this link for this post.
I showed previously how to create an Options menu and how to add Menu item to it.
Now I am going to show how to handle options menu item selection.
I will show code snippet and after whole example. Read more…