There is a problem, that in custom view SimpleOnGestureListener onFling is not called.
Solution is - implement GestureDetector.OnGestureListener and always return true from onDown(MotionEvent e) method, which will lead to onFling and onScroll being called.
Sunday, November 7, 2010
Tuesday, November 2, 2010
Disabling AlertDialog button
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setPositiveButton(getString(R.string.save),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int whichButton)
{
}
});
AlertDialog dialog = dialogBuilder.create();
dialog.show();
Button button = dialog.getButton(Dialog.BUTTON_POSITIVE);
button.setEnabled(false);
Trick is to call dialog.getButton(...) after dialog.show(), otherwise it will return null.
Thursday, October 28, 2010
ScrollView with button below
To place button below ScrollView I use following XML:
Advantage of this solution - no need to specify button size or any margins in dp.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e77d89">
<Button
android:layout_alignParentBottom="true"
android:id="@+id/close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/close"
/>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/close"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
style="@style/HelpText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/help_part_1"
/>
<TextView
style="@style/HelpText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/help_part_2"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Advantage of this solution - no need to specify button size or any margins in dp.
Tuesday, October 26, 2010
Vertical textview (rotated by 270 degrees)
Here is excellent and working example: http://stackoverflow.com/questions/1258275/vertical-rotated-label-in-android
How to change language/locale within Android application
If you want to change language/locale from your Android application (not in system settings), following code works for me:
public void changeLocale(Locale locale) {
Locale.setDefault(locale);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = locale;
res.updateConfiguration(conf, dm);
finish();
Intent intent = new Intent(getApplicationContext(),
this.getClass());
intent.setAction(Intent.ACTION_CONFIGURATION_CHANGED);
startActivity(intent);
}
Subscribe to:
Posts (Atom)