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>

分类:Mobile 时间:2010-07-05 人气:276
分享到:
blog comments powered by Disqus

相关文章

  • Java学习之Xml系列六:Dom4j--专题1:基于DOM树的增删改查 2014-08-21

    全在注释里. dtd文档: <?xml version="1.0" encoding="UTF-8"?> <!ELEMENT SwordLibrary (Sword*)> <!ELEMENT Sword (SwordName,Price,Attack)> <!ELEMENT SwordName (#PCDATA)> <!ELEMENT Price (#PCDATA)> <!ELEMENT Attack

  • java code for the return JSON or XML data (extJs) 2010-06-10

    package com.hrm.util; import java.util.ArrayList; import java.util.List; import net.sf.json.JSONObject; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; /** * Title: Ext JS Auxiliary classes * Description: Th

  • Agile Development of Java code to write high-quality 2009-12-24

    Agile development concept has been popular for a very long time, the development of agile development iteration stage, we can through the five steps to effectively improve the quality of the entire project code. Java project development process, due

  • [Change] agile development of high-quality Java code to write 2009-09-29

    Agile development concept has been popular for a very long time, the development of agile development iteration stage, we can through the five steps to effectively improve the quality of the entire project code. Java project development process, due

  • WebService development example (java code) 2010-03-19

    WebService is an advanced application, with the previous learning Struts, Spring, Hibernate and other frameworks different. WebService is a service-oriented architecture (SOA), looks like a larger framework than SSH. In the end it is what for? What i

  • Agile Java code to write high-quality 2010-03-10

    Source: IBM dW / Wang Yongkui | De idea of agile development has been popular for a long time in Agile Development Kaifa iteration stage, we can through the five steps to effectively improve the entire project code quality. Java project development p

  • Java code using JDEE as a reader 2010-04-06

    Emacs is absolutely great software, some shameless villain than the secular far to great, but some of its design to the letter and still affect a lot of development tools. JDEE is a great software, I JDEE mailing list, get feedback very very happy: W

  • java Code Generation 2010-05-01

    1. Generated verification code: using technology jsp, servlet 2. Generated verification code in the servlet: package servlet; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.I

  • Typical Java code for the thread pool and various parts of Features 2010-05-08

    (1) According to the xml file to manage the thread pool's maximum and minimum number of threads (2) Timer on a regular basis by scanning the thread pool to prevent the thread is not active; (3) by a single variable (in this procedure is freeThreadCou

  • ORACLE statements in Java code to perform insert operation error: ORA-00911: invalid character 2010-05-12

    For insert operations sql: INSERT INTO FB10_COLLIGATE_SATAISTIC (colligate_statistic_id, inner_code, report_date) VALUES (COLLIGATE_STATISTIC_ID_SEQ.NEXTVAL, #innerCode#, #reportDate#); Problem description: sql is simple to insert data into a table a

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.514 (s). 10 q(s)