目錄html
參考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安裝 Android Stuidiojava
參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:android
參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:git
參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:app
參考《Java和Android開發學習指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:ide
本次實驗就是一個學習的過程,其實實驗步驟指導書中都已經有了詳細的說明,因此我就對本次實驗所學到的內容進行小結。佈局
調試學習
startActivity(intent)
intent.putExtra("message","Message from first screen")
Intent intent = getIntent(); String Message = intent.getStringExtra("message");
<Button android:id="@+id/saveButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:layout_centerHorizontal="true" android:text="Speak"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!\n20175313\n20175312\n20175314" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />
public Toast(android.content.Context context)
public static Toast makeText(android.content.Context context,int resourceId,int duration)
public static Toast makeText(android.content.Context context,java.lang.CharSequence text,int duration)
Toast.makeText(this,"Downloading…",Toast.LENGTH_LONG).show();
想要讓程序響應某個事件,須要爲該事件編寫一個監聽器,即接口的實現。測試
接口的實現有兩種方法:ui
方法一:使用匿名類實現接口
button.setOnClickListener(new OnClickListener(){//與接口有關的匿名類 @Override public void onClick(View v){ Toast.makeText(MainActivity.this, "20175313", Toast.LENGTH_LONG).show(); } });
方法二:在主類中實現接口,並重寫方法
public class MainActivity extends AppCompatActivity implements View.OnTouchListener {……}
public boolean onTouch(View arg0, MotionEvent event){ Intent intent = new Intent(this,ThirdActivity.class); intent.putExtra("message","20175313"); startActivity(intent); return true; }