標題:
隨堂測驗0629
[打印本頁]
作者:
顏子翔
時間:
2019-6-29 10:54
標題:
隨堂測驗0629
本日隨堂測驗 107 108
作者:
黃璽安
時間:
2019-6-29 10:54
package com.tqc.gdd01;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class GDD01 extends Activity
{
private static final String TAG = "Android_Log";
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1999)
tv.setText(resultCode+" ");
}
private TextView tv;
private Button b1;
private Button b2;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView) findViewById(R.id.text1);;
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Intent it = new Intent(GDD01.this, GDD01_2.class);
startActivityForResult(it, 1999);
}
});
b2.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
finish();
}
});
Log.i(TAG, "onCreate");
}
@Override
public void onStart(){
super.onStart();
Log.i(TAG, "onStart");
}
@Override
public void onResume(){
super.onResume();
Log.i(TAG, "onResume");
}
@Override
public void onPause(){
super.onPause();
Log.i(TAG, "onPause");
}
@Override
public void onStop(){
super.onStop();
Log.i(TAG, "onStop");
}
@Override
public void onRestart(){
super.onRestart();
Log.i(TAG, "onRestart");
}
@Override
public void onDestroy(){
super.onDestroy();
Log.i(TAG, "onDestroy");
}
}
複製代碼
package com.tqc.gdd01;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* Created by student on 2019/6/22.
*/
public class GDD01_2 extends Activity{
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
Button btn = (Button) findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setResult(99);
finish();
}
});
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.tqc.gdd01"
xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.tqc.gdd01.GDD01"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".GDD01_2"></activity>
</application>
</manifest>
複製代碼
作者:
李知易
時間:
2019-6-29 10:55
package com.tqc.gdd01;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class GDD01 extends Activity
{
private static final String TAG = "Android_Log";
private TextView tv;
private Button b1;
private Button b2;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1999)
{
tv.setText(resultCode + "");
}
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView) findViewById(R.id.text1);;
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent(GDD01.this,GDD01_2.class);
startActivityForResult(intent,1999);
}
});
b2.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
finish();
}
});
Log.i(TAG, "oncreate()");
}
@Override
public void onStart(){
super.onStart();
Log.i(TAG, "onStart()");
}
@Override
public void onResume(){
super.onResume();
Log.i(TAG, "onResume()");
}
@Override
public void onPause(){
super.onPause();
Log.i(TAG, "onPause()");
}
@Override
public void onStop(){
super.onStop();
Log.i(TAG, "onStop()");
}
@Override
public void onRestart(){
super.onRestart();
Log.i(TAG, "onRestart()");
}
@Override
public void onDestroy(){
super.onDestroy();
Log.i(TAG, "onDestroy()");
}
}
複製代碼
package com.tqc.gdd01;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* Created by student on 2019/6/15.
*/
public class GDD01_2 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
Button btn =(Button)findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setResult(99);
finish();
}
});
}
}
複製代碼
作者:
張健勳
時間:
2019-6-29 10:56
TQC+ 107
package com.tqc.gdd01;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class GDD01 extends Activity
{
private static final String TAG = "Android_Log";
private TextView tv;
private Button b1;
private Button b2;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.i(TAG, "onCreate");
tv=(TextView) findViewById(R.id.text1);;
b1 = (Button) findViewById(R.id.button1);
b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Intent it = new Intent();
it.setClass(GDD01.this,GDD01_2.class);
GDD01.this.startActivityForResult(it,0);
}
});
b2.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
GDD01.this.finish();
}
});
}
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data)
{
tv.setText(""+resultCode);
}
@Override
public void onStart(){
super.onStart();
Log.i(TAG, "onStart");
}
@Override
public void onResume(){
super.onResume();
Log.i(TAG, "onResume");
}
@Override
public void onPause(){
super.onPause();
Log.i(TAG,"onPause");
}
@Override
public void onStop(){
super.onStop();
Log.i(TAG,"onStop");
}
@Override
public void onRestart(){
super.onRestart();
Log.i(TAG,"onRestart");
}
@Override
public void onDestroy(){
super.onDestroy();
Log.i(TAG,"onDestory");
}
}
複製代碼
package com.tqc.gdd01;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.tqc.gdd01.R;
public class GDD01_2 extends Activity {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.mylayout);
btn = (Button) this.findViewById(R.id.button2);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
GDD01_2.this.setResult(99, GDD01_2.this.getIntent());
GDD01_2.this.finish();
}
});
}
}
複製代碼
作者:
李知易
時間:
2019-6-29 11:16
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@color/white"
>
<EditText
android:id="@+id/mAccount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/black"
android:hint="@string/str1"
android:inputType="number"
/>
<EditText
android:id="@+id/mPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/black"
android:hint="@string/str2"
android:inputType="textPassword"
/>
<CheckBox
android:id="@+id/mCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="顯示密碼"
/>
</LinearLayout>
複製代碼
package com.tqc.gdd01;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.accessibility.AccessibilityManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
public class GDD01 extends Activity implements CompoundButton.OnCheckedChangeListener {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CheckBox mcheck = (CheckBox)findViewById(R.id.mCheck);
mcheck.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
EditText pw = (EditText)findViewById(R.id.mPassword);
if(isChecked)
{
pw.setInputType(InputType.TYPE_CLASS_TEXT);
}else
{
pw.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
}
複製代碼
作者:
黃璽安
時間:
2019-6-29 11:16
package com.tqc.gdd01;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputType;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
public class GDD01 extends Activity implements CompoundButton.OnCheckedChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
CheckBox mCheck = (CheckBox) findViewById(R.id.mCheck);
mCheck.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
EditText pw = (EditText) findViewById(R.id.mPassword);
if(isChecked){
pw.setInputType(InputType.TYPE_CLASS_TEXT);
}else{
pw.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@color/white"
>
<EditText
android:id="@+id/mAccount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/black"
android:hint="@string/str1"
/>
<EditText
android:id="@+id/mPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/black"
android:hint="@string/str2"
/>
<CheckBox
android:id="@+id/mCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:hint="@string/str3"
/>
</LinearLayout>
複製代碼
作者:
張健勳
時間:
2019-6-29 11:27
package com.tqc.gdd01;
import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
public class GDD01 extends Activity {
private EditText edittext;
private CheckBox checkbox;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
checkbox = (CheckBox) findViewById(R.id.mCheck);
checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
edittext = (EditText) findViewById(R.id.mPassword);
if (checkbox.isChecked()) {
edittext.setInputType(InputType.TYPE_CLASS_TEXT);
} else {
edittext.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
});
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2