まさか蜜葉がブログのカテゴリにJavaなんて入れる事になろうとは!!!
とりあえず、ボタンイベントまでは試してみたかったのでやってみた。
layout>main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:text="@string/textView" android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:text="@string/button_name" android:id="@+id/Button01" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
values>strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="hello">Hello World, Hello!</string> <string name="app_name">Hello android</string> <string name="button_name">Button</string> <string name="textView">ButtonEvent_test</string> </resources>
src>org.test.hello>Hello.java
package org.test.hello; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Hello extends Activity { /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /** idを探してきて、Buttonクラスのbに登録*/ Button b = (Button)findViewById(R.id.Button01); /**クリックリスナー作成*/ ClickListener listener = new ClickListener(); /**Button01にイベントを登録*/ b.setOnClickListener(listener); } /**Button01のイベントハンドラ*/ class ClickListener implements OnClickListener { Boolean key = true; public void onClick(View v) { Button b = (Button)v; if(key == true){ b.setText("Button"); key = false; }else{ b.setText("Hello Android"); key = true; } } } }
さすがJava....イベント処理ぐらいButtonクラスに標準でつけろよ!って思っても、そこはやっぱりJava...orz
んー。触ってみた感じ、敷居は低いけど、やっぱりJavaに慣れてないとしんどいなぁ。
やぱJavaすきになれそうにない(ぁ