ã¯ããã«
ãä»åã¯ãµã³ãã«ã¢ããªã±ã¼ã·ã§ã³ã®ç»é¢ã¬ã¤ã¢ã¦ããä½æãã¦ããã¾ããæ¬ç¨¿ã®ä½æ¥ãè¡ã£ãç¶æ
ã®ããã¸ã§ã¯ãããµã³ãã«ã½ã¼ã¹ã¨ãã¦ç¨æããã®ã§ãè¿·ã£ãå ´åã¯åèã«ãã¦ãã ããã
対象èªè
ãæ¬é£è¼ã¯Javaããã³Eclipseã®åºæ¬ãç解ãã¦ããæ¹ã対象ã¨ãã¦ãã¾ãã
ååã®è¨äº
- 第1åãAndroidã®æ¦è¦ã¨éçºç°å¢ã®æ§ç¯
- 第2åãæä½éããã ãç¥ã£ã¦ããã°OKï¼ Androidã¢ããªéçºã®åºç¤ç¥è
äºåæºå
ãã¾ãã¯ãä»å使ç¨ããã¤ã¡ã¼ã¸ãã¡ã¤ã«ãæºåãã¾ããããã¤ã¡ã¼ã¸ãã¡ã¤ã«ã¯ããdrawable-***ããã©ã«ãã«ç½®ããã¨ã§è§£å度ãã¨ã«å¥ã®ãã¡ã¤ã«ã使ç¨ãããã¨ãã§ãã¾ãããä»åã¯åãã¤ã¡ã¼ã¸ãã¡ã¤ã«ã使ç¨ãã¾ããã¤ã¡ã¼ã¸ãã¡ã¤ã«ããã¦ã³ãã¼ããããã解åããä¸ã«ãããdrawableããã©ã«ãããresããã©ã«ãã®ç´ä¸ã«é ç½®ãã¦ãã ããã
ä¸è¦§ç»é¢ã®ã¬ã¤ã¢ã¦ãä½æ
ãããã§ã¯ãä¸è¦§ç»é¢ã®ã¬ã¤ã¢ã¦ãããä½æãã¦ããã¾ãããã
ãä¸è¦§è¡¨ç¤ºã«ã¯ãListViewã¨ããé¨åãå©ç¨ãã¾ãããres/layout/main.xmlããéãã次ã®ããã«TextViewãListViewã«å¤æ´ãã¾ãã
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- ä¸è¦§è¡¨ç¤ºç¨ãªã¹ã --> <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
ãListViewã§æå®ãã¦ããå±æ§ã¯ä¸è¨ã®æå³ãæã¡ã¾ãã
å±æ§ | æå³ |
---|---|
android:id | ããã°ã©ã ãããã¥ã¼ãåç §ããããã®ID |
layout_width | ãã¥ã¼ã®å¹ ãfill_parentã§è¦ªãã£ã±ãã«åºãã |
layout_height | ãã¥ã¼ã®é«ããfill_parentã§è¦ªãã£ã±ãã«åºãã |
ãããã§ä½¿ç¨ãã以å¤ã«ãããã¥ã¼ã¯ãã¾ãã¾ãªå±æ§ãæå®ãããã¨ãå¯è½ã§ããå±æ§ã®è©³ç´°ã«ã¤ãã¦ã¯ä¸è¨ãåç §ãã ããã
- Class Indexãªãã¡ã¬ã³ã¹ï¼Android Developers
- Android Wiki
ããã®ç¶æ ã§å®è¡ããã¨ãã¿ã¤ãã«ã ãã®ç©ºã®ç»é¢ã表示ããã¾ãããªãããVirtual Deviceãã®è¨å®ãã¦ããªãå ´åã¯ã第1åãåèã«ãã¦ãè¨å®ãã¦ãã ããã
ããããããã¾ãå®è¡ã§ããªãããã§ããã°Eclipseã®ãConsoleããã¥ã¼ããã³ããLogCatããã¥ã¼ï¼ï¼»Windowï¼½-ï¼»Show Viewï¼½-ï¼»Otherï¼½-ï¼»Androidï¼½-ï¼»LogCatï¼½ã§è¡¨ç¤ºï¼ã§åå ãç¹å®ãã¦ãã ããã
ããã®ç¶æ ã§ã¯ã¬ã¤ã¢ã¦ããæ£ããã§ãã¦ããã®ã確èªã§ããªãã®ã§ãListViewã«ã¢ã¤ãã ãè¨å®ãã¦ã¿ã¾ããããListActivityãéãã¦æ¬¡ã®ããã«æ¸ãæãã¦ãã ããã
/** * ä¸è¦§è¡¨ç¤ºã¢ã¯ãã£ãã㣠*/ public class ListActivity extends Activity { // ä¸è¦§è¡¨ç¤ºç¨ListView private ListView listView = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // èªåçæãããR.javaã®å®æ°ãæå®ãã¦XMLããã¬ã¤ã¢ã¦ããçæ setContentView(R.layout.main); // XMLã§å®ç¾©ããandroid:idã®å¤ãæå®ãã¦ListViewãåå¾ãã¾ãã listView = (ListView) findViewById(R.id.list); // ListViewã«è¡¨ç¤ºããè¦ç´ ãä¿æããã¢ããã¿ãçæãã¾ãã ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); // è¦ç´ ã追å arrayAdapter.add("æ°è¦è¿½å "); // ã¢ããã¿ãè¨å® listView.setAdapter(arrayAdapter); } }
ããã®ç¶æ ã§å度å®è¡ããã¨ãListViewã«ãæ°è¦è¿½å ãã¨ããè¦ç´ ã表示ãããã¬ã¤ã¢ã¦ããæ£ããã§ãã¦ãããã¨ã確èªã§ãã¾ãã