Question mark (?) in XML attributes for Android

Can anyone explain the question mark means in Android XML attributes?

    More attributes


The question mark means it’s a reference to a resource value in the currently applied theme. See the linuxtopia Android Dev Guide or the Dev Guide for more about it.

? escapes the question mark.


Android file-creation fails

I use the following code to create a folder “mymir” and a file “.nomedia” (in the mymir-folder) on the sdcard of an android unit. However, somehow it fails with the exception that the folder the “.nomedia”-file is to be placed in dosn’t exist. Here’s the code:

private String EnsureRootDir() throws IOException
    File sdcard = Environment.getExternalStorageDirectory();
    File mymirFolder = new File(sdcard.getAbsolutePath() + "/mymir/");
        File noMedia = new File(mymirFolder.getAbsolutePath() + "/.nomedia");
    return mymirFolder.getAbsolutePath();


I SD really there?

Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) == true

If targeting 1.6+, have you declared

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

The exact Exception could help.


Simple example of and usage in Android XML-layouts

I’m curious about the <merge> and <include> tags in Android XML-layouts. I’ve read two tutorials, but haven’t yet found a simple example usage.

Would be happy if someone could provide such an example or give a pointer to one.



<LinearLayout xmlns:android=""
    android:layout_width="fill_parent" android:layout_height="fill_parent"

    // some views

    <include layout="@layout/view_part"/>

   // probably more views



<merge xmlns:android="">

    // the views to be merged


How to hide optgroup/option elements?

Is there a way to hide option or optgroup HTML elements? I’ve tried calling hide() in jQuery, and also using regular Javascript to set style.display='none'.

It works in Firefox but not in any other browsers. Actually removing them from the DOM does work, so perhaps there’s a way to save each DOM element when it’s removed, and reinsert them in the same place?

My HTML is like this:

<select name="propsearch[area]" id="propsearch_area">
    <option value="0">- Any -</option>
    <optgroup label="Bristol">
        <option  value="Hotwells">Hotwells</option>
        <option  value="Montpelier">Montpelier</option>
    <optgroup label="Cardiff">
        <option  value="Heath">Heath</option>
        <option  value="Roath">Roath</option>
    <optgroup label="Exeter">
        <option  value="Pennsylvania Road">Pennsylvania Road</option>
        <option  value="Lower North Street">Lower North Street</option>
    <optgroup label="Swansea">
        <option  value="Brynmill">Brynmill</option>
        <option  value="Uplands">Uplands</option>


I figured that this solution works fine for me:

Make another select e.g.

$("#footer_canvas").after('<select id="parkingLot"></select>');

then hide it


When you want to ‘hide’ some optgroup, just ‘park’ it in this hidden select.

$('#VehicleVehicleCategoryId optgroup[label="kategorie L"]').appendTo("#parkingLot");

Same way you can make it visible. This is just the snippets of my solution, that works fine for me.


Android: Programmatically animate between images in Gallery widget

Note: As of Jellybean the gallery widget is deprecated. A ViewPager should be used instead.

I’d like to programmatically move between images in the Gallery widget, with animation.

I can change the currently displaying image using the setSelection(int position) method, however that does not animate. Then there’s setSelection(int position, bool animate) but the extra boolean on the end there doesn’t appear to do anything.

In the source of Gallery it appears that it can handle DPAD key-presses, so a work-around I thought of was to fake the key-presses. Eg.

dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT))

However I can’t get this working for some reason. Anyone tried this?

I notice three of the widget’s methods I’d love to use moveNext(), movePrevious() and scrollToChild() are all private and unusable.

Does anyone know how I might be able to do this?


Just call the key press handler for the gallery directly:

public boolean onKeyDown(int keyCode, KeyEvent event)


Gallery gallery = ((Gallery) findViewById(;

gallery.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, new KeyEvent(0, 0));

One important thing – this solution works only if child that is on left/right was already created, which means that it has to be ‘visible’. If you have your image on fullscreen – consider setting spacing to -1 value.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..