How to set a default item in a spinner drop down list

by MMC2 » Tue, 26 Jan 2010 21:10:21 GMT

Sponsored Links
 How can I use code to set a default item in a spinner drop down list


Other Threads

1. simulate fling up using TouchUtils.drag() does not work on Gingerbread


I have a simple Activity that populates a list.  I simulated the fling
up action so that the list scrolls down using Android
TouchUtils.drag(InstrumentationTestCase test, float fromX, float toX,
float fromY, float toY, int stepCount) API.

The simulation works on a Froyo device.  I can see the list being
scrolled down when the test ran.  But the same test does not work on
Gingerbread device.  The app is launched, but the list is not being
scrolled down at all.   Do you know if it's an issue with Gingerbread
or I need to update my code?

The screen size of both phones are about the same.  So, I don't think
it's the X and Y coordinates that are incorrect.

The app code:
public class ListViewApp extends ListActivity {
        private static String[] items = { "item1", "item2", "item3", "item3",
                        "item4", "item5", "item6", "item7", "item8", "item9", 
                        "item11", "item12", "item13", "item14", "item15" , 
"i16", "i17",
"i18", "i19"};
                public void onCreate(Bundle savedInstanceState) {

                        setListAdapter(new ArrayAdapter<String>(this,
                                R.layout.list_view_example, items));

The test app:

public class ListViewTests extends
ActivityInstrumentationTestCase2<ListViewApp> {
        private ListViewApp activity;
        private Instrumentation instr;
        private Context context;
        private int screenWidth = 0;
        private int screenHeight = 0;
        private int[] xy = new int[2];

        public ListViewTests() {
                super("", ListViewApp.class);

        protected void setUp() throws Exception {

                Log.d(TestUtil.TAG, this.getClass().getName() + ".setUp()");

                 * prepare to send key events to the app under test by turning 
                 * mode. Must be done before the first call to getActivity()


                activity = getActivity();

                instr = getInstrumentation();
                assertNotNull("Instrumentation is null.", instr);

                context = instr.getContext();
                assertNotNull("Context is null", context);

                screenWidth = activity.getWindowManager().getDefaultDisplay()
                screenHeight = activity.getWindowManager().getDefaultDisplay()

                Log.d(TestUtil.TAG, "screenWidth: " + screenWidth + " 
                                + screenHeight);
                // to safeguard against grip suppression, don't get too close 
to the
                xy[0] = screenWidth/4;
                xy[1] = screenHeight/10;
                Log.d(TestUtil.TAG, "X coordinate: " + xy[0] + " Y coordinate: "
                                + xy[1]);


                // waiting for app to load
                try {
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block

        protected void tearDown() throws Exception {
                Log.d(TestUtil.TAG, this.getClass().getName() + ".tearDown()");


         * Launch the app and fling up to scroll down the list
        public void testFlingUp() {

                int fromX, toX, fromY, toY = 0;

                fromX = xy[0];
                toX = fromX;
                fromY = (screenHeight - 60);
                toY = (screenHeight / 2);

                TouchUtils.drag(this, fromX, toX, fromY, toY, 1);
                try {
                } catch (InterruptedException e) {
                        // TODO Auto-generated catch block


2. jar.libs.dir is the new external.libs.dir?

I upgraded to ADT 8 and my projects wouldn't build with Ant any more , 
failing with a lot of class not found errors. 
I have a file with the following contents:


A quick grep for the rules files shows that 'external.libs.dir' is not used 
any more. It seems it 
has been replaced by 'jar.libs.dir'. This doesn't seem to be documented 
anywhere, so are we supposed 
to use 'jar.libs.dir' from now on? If so, a simple

<property name="external.libs.dir" value="${jar.libs.dir}" />

or something would be nice, so that people's builds don't break all of a 


3. Regarding emulator.exe has encountered a problem and needs to close. We are sorry for the inconvenience.

4. Completely disable Soft Keyboard from EditText

5. what is Third party application server??

6. Intriguing focus problem with PreferenceActivity

7. How do I interact with different music player?