Eclipse Development Android, Hello Spinner (learning 10)

Eclipse Development Android, Hello Spinner (learning 10)


Keywords: hellospinner

HelloSpinner.java Source

Java code
  1. package com.example.test;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.widget.ArrayAdapter;
  5. import android.widget.Spinner;
  6. public class HelloSpinner extends Activity (
  7. @ Override
  8. public void onCreate (Bundle savedInstanceState) (
  9. super. onCreate (savedInstanceState);
  10. setContentView (R.layout.main);
  11. Spinner s = (Spinner) findViewById (R.id.spinner);
  12. ArrayAdapter adapter = ArrayAdapter.createFromResource (
  13. this, R.array.planets, android.R.layout.simple_spinner_item);
  14. adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
  15. s.setAdapter (adapter);
  16. )
  17. )

package com.example.test;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class HelloSpinner extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            Spinner s = (Spinner) findViewById(R.id.spinner);
            ArrayAdapter adapter = ArrayAdapter.createFromResource(
                    this, R.array.planets, android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            s.setAdapter(adapter);
        }

}

layout-> main.xml

Xml Code
  1. <? Xml version = "1.0" encoding = "utf-8"?>
  2. <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
  3. android: orientation = "vertical"
  4. android: padding = "10dip"
  5. android: layout_width = "fill_parent"
  6. android: layout_height = "wrap_content">
  7. <TextView
  8. android: layout_width = "fill_parent"
  9. android: layout_height = "wrap_content"
  10. android: layout_marginTop = "10dip"
  11. android: text = "Please select a planet:"
  12. />
  13. <Spinner
  14. android: id = "@ + id / spinner"
  15. android: layout_width = "fill_parent"
  16. android: layout_height = "wrap_content"
  17. android: drawSelectorOnTop = "true"
  18. android: prompt = "@ string / planet_prompt"
  19. />
  20. </ LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:padding="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dip"
        android:text="Please select a planet:"
    />

    <Spinner 
        android:id="@+id/spinner"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:drawSelectorOnTop="true"
        android:prompt="@string/planet_prompt"
    />

</LinearLayout>

values-> arrays.xml

Xml Code
  1. <Resources>
  2. <String-array name = "planets">
  3. <Item> Mercury </ item>
  4. <Item> Venus </ item>
  5. <Item> Earth </ item>
  6. <Item> Mars </ item>
  7. <Item> Jupiter </ item>
  8. <Item> Saturn </ item>
  9. <Item> Uranus </ item>
  10. <Item> Neptune </ item>
  11. </ String-array>
  12. </ Resources>

<resources>

    <string-array name="planets">
        <item>Mercury</item>
        <item>Venus</item>
        <item>Earth</item>
        <item>Mars</item>
        <item>Jupiter</item>
        <item>Saturn</item>
        <item>Uranus</item>
        <item>Neptune</item>
    </string-array>
    
</resources>

value-> strings.xml

Xml Code
  1. <? Xml version = "1.0" encoding = "utf-8"?>
  2. <Resources>
  3. <String name = "hello"> Hello World, HelloSpinner! </ String>
  4. <String name = "app_name"> HelloSpinner </ string>
  5. <String name = "planet_prompt"> Choose a planet </ string>
  6. </ Resources>

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, HelloSpinner!</string>
    <string name="app_name">HelloSpinner</string>
        <string name="planet_prompt">Choose a planet</string>
</resources>


run it Eclipse Development Android, Hello Spinner (learning 10)

<string-array name="province">
<item value="1"> Hunan </ item>
<item value="2"> Guangzhou </ item>
<item value="3"> Shanghai </ item>
</ String-array>
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Eclipse Development Android, Hello Spinner (learning 10)

  • JAVA EE JSP_JNDI

    dsfdsa http://lindows.javaeye.com/admin/blogs/213348 Tomcat 6 with the connection pool data source configuration http://www.blogjava.net/ec2008/archive/2008/07/19/216063.html project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...

  • Hibernate.cfg.xml configuration file (including the primary key generation strategy Introduction)

    Hibernate.cfg.xml configuration file: <? xml version = "1.0" encoding = "utf-8"?> <! DOCTYPE hibernate-configuration PUBLIC "- / / Hibernate / Hibernate Configuration DTD / / EN" "hibernate-configuration-2.0.dtd

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • Servlet brief introduction

    Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...

  • Spring2.0 + hibernate3.1 + log4j + mysql demo

    applicationContext.xml Non-attachment jar package, necessary friends can send an email to todd.liangt @ gmail.com

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries