package jp.ac.nc_toyama.chap8_1_1; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends ActionBarActivity { private int protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ((Button) findViewById(R.id.button)).setOnClickListener( new View.OnClickListener(){ public void onClick(View view){ ((TextView) findViewById(R.id.textView)).setText(String.format(“%d times”,++i)); } }); } }">
Download presentation
Presentation is loading. Please wait.
1
創造工学設計 I 電子情報工学科4年(前期) 10回目 ( 25/6/2015) 担当 古山彰一 (shoichi@nc-toyama.ac.jp)
2
Chap8_1_1 と Chap8_1_3 には エラーがあります。 修正してください。 ※ Chap8_1_1 は簡単です。 Chap8_1_3 は Chap8_1_6 のプログラムがヒントになるか も?
3
クリックされた回数をカウントするアプリ textView : id: @+id/textView Text: ボタンをタップした回数を数え ます Button: id: @+id/button1 Text: Please tap! <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${packageName}.${activityClass}"> <TextView android:text=" ボタンをタップした回数を数えます。 " android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Please tap!" android:id="@+id/button1" android:layout_below="@+id/textView" android:layout_alignParentLeft="true" /> package jp.ac.nc_toyama.chap8_1_1; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends ActionBarActivity { private int i=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ((Button) findViewById(R.id.button)).setOnClickListener( new View.OnClickListener(){ public void onClick(View view){ ((TextView) findViewById(R.id.textView)).setText(String.format(“%d times”,++i)); } }); } }
4
Button Id: @+id/button Text: START! package jp.ac.nc_toyama.chap8_1_3; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.view.animation.CycleInterpolator; import android.view.animation.ScaleAnimation; import android.widget.Button; public class MainActivity extends ActionBarActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // ((Button) findViewById(R.id.button)).setOnClickListener(new View.onClickListener(){ // @Override public void onClick(View view){ ScaleAnimation scale = new ScaleAnimation( 0.5f, 10.0f, 0.5f, 10.0f, view.getWidth()/2, view.getHeight()/2 ); // scale.setDuration(1000); // scale.setInterpolator(new CycleInterpolator(0.5f)); // view.startAnimation(scale); } }); } } ボタンにアニメーションをさ せる
5
トーストに現在時刻を表示する Button Id: @+id/button Text: 日付と時 刻を表示します <RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> package jp.ac.nc_toyama.chap8_1_6; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import java.text.SimpleDateFormat; import java.util.Date; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener(){ public void onClick(View view){ // SimpleDateFormat sdfFormat = new SimpleDateFormat("yyyy.MM.dd '/' a hh:mm:ss"); // Date dateTime = new Date(); // Toast tstToast = Toast.makeText( getApplicationContext(), sdfFormat.format(dateTime), Toast.LENGTH_LONG); tstToast.show(); } }); } }
6
課題について 課題1: 以下の表ではイベントリスナーとコールバックメソッドを表にしたものだが、内容の部分を記入 しなさい。 課題2: Chap8_1_3 の中で、 setInterpolator() メソッドを用いてい るが、その引数に指定できるオブ ジェクトとして右表のようなもの がある。説明をしなさい。また、 実際にプログラムに挿入して動作 を確認しなさい。 クラス名説明 AccelerateInterpolator DecelerateInterpolator AccelerateDecelerateInterpolator AnticipateInterpolator AnticipateOvershootInterpolator BounceInterpolator CycleInterpolator LinearInterpolator OvershuootInterpolator
7
課題1~3を pdf ファイルにしてメールで提出しなさい。 締切 本日中 (23:59 まで ) 提出先 shoichi@nc-toyama.ac.jp shoichi@nc-toyama.ac.jp 課題ファイル名 10i4??.pdf (?? は二桁の出席番号 ) 課題3: 本日作成した3つのプログラムの方法を応用して、自分なりのアプリを作成しなさい。
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.