Alert messagebox toast Android example code
Toast in Android application is equivalent of Alert in JavaScript or MessageBox in WinApi.
// Toast android.widget.Toast.makeText(Context context, CharSequence text, int duration)
// public static Toast makeText (Context context, CharSequence text, int duration)
Toast.makeText(getApplicationContext(), "Hello world!",
Toast.LENGTH_SHORT).show();
396LW NO topic_id
AD
Další témata ....(Topics)
public class MainActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
RadioGroup radioGroup = new RadioGroup(this);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
layout.addView(radioGroup, p);
RadioButton radioButtonView = new RadioButton(this);
radioButtonView.setText("RadioButton");
radioButtonView.setOnClickListener(this);
radioGroup.addView(radioButtonView, p);
RadioButton radioButtonView2 = new RadioButton(this);
radioButtonView2.setText("RadioButton2");
radioButtonView2.setOnClickListener(mThisButtonListener);
radioGroup.addView(radioButtonView2, p);
}
public void onClick(View view) {
try {
String s = ((RadioButton) view).getText().toString();
Toast.makeText(MainActivity.this, "This is: " + s,
Toast.LENGTH_LONG).show();
}
catch (Exception e1) {
e1.printStackTrace();
}
}
private OnClickListener mThisButtonListener = new OnClickListener() {
public void onClick(View v) {
String s = ((RadioButton) v).getText().toString();
Toast.makeText(MainActivity.this, "Hello from 2!" + s,
Toast.LENGTH_LONG).show();
}
};
}
If You have old PC (Android in emulator with high screen resolution uses a lot of memory) or your testing phone have small screen, You can try this trick.
Rename layout folder for small device screen f.g. from layout into layout-swXXXdp and a large layout-sw600dp into layout.
Your phone with small screnn will do select xml file from renamed layout folder (for small screen).
You can to testing rotation with device en stability of fragments if an application changed orientation.
If you have old pc, you can try to make a new virtual device running on older version of Android, which uses less memory of computer.
For testing of rotation stability - application orientation changed - use on emulator Ctrl+F11, Ctrl+F12 key (Windows).
Important
Before the release of application, you have to rename layout folder to older name layout-sw600dp and layout-swXXXdp to layout.
Rename layout folder for small device screen f.g. from layout into layout-swXXXdp and a large layout-sw600dp into layout.
Your phone with small screnn will do select xml file from renamed layout folder (for small screen).
You can to testing rotation with device en stability of fragments if an application changed orientation.
If you have old pc, you can try to make a new virtual device running on older version of Android, which uses less memory of computer.
For testing of rotation stability - application orientation changed - use on emulator Ctrl+F11, Ctrl+F12 key (Windows).
Important
Before the release of application, you have to rename layout folder to older name layout-sw600dp and layout-swXXXdp to layout.
Not request focus EditText if startup Android - hide keyboard if startup.
Remove: from EditText
Create a LinearLayout and set the:
attributes android:focusable="true" android:focusableInTouchMode="true"
Remove:
Create a LinearLayout and set the:
attributes android:focusable="true" android:focusableInTouchMode="true"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
</LinearLayout>
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Error parsing the sdk.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Failed to create C:\Program Files\android\sdk\add-ons.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Unable to parse SDK content.
You have to create add-ons folder as admin of PC
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Failed to create C:\Program Files\android\sdk\add-ons.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Unable to parse SDK content.
You have to create add-ons folder as admin of PC
Editace: 2011-09-16 11:29:29
Počet článků v kategorii: 396
Url:alert-messagebox-toast-android-example-code