hoocy 发表于 2013-1-15 02:49:05

android_学习练习2

 
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"    ><TextViewandroid:id="@+id/show_TextView"    android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:text="@string/hello"    /><Button android:id="@+id/Click_Button"android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:text="点击"    />    </LinearLayout> 
ButtonViewTest.java
 
package com.hoocy;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.TextView;public class ButtonViewTest extends Activity {    /** Called when the activity is first created. */private TextView show;private Button press;    @Override    public void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.main);                show=(TextView) findViewById(R.id.show_TextView);      press = (Button) findViewById(R.id.Click_Button);                press.setOnClickListener(new Button.OnClickListener(){public void onClick(View v) {show.setText("hi.welcome you! www.163.com");}      });    }} 
 
 
 
 
练习2
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"    ><TextViewandroid:layout_height="wrap_content"   android:layout_width="fill_parent"   android:id="@+id/TextView_Guide"    android:textSize="25px"    android:text="@string/advice"    /><TextViewandroid:layout_height="wrap_content"android:layout_width="fill_parent"android:id="@+id/TextView_youChoiceShow"android:textSize="25px"/>    <CheckBox android:layout_height="wrap_content"android:layout_marginTop="100px"android:layout_marginLeft="90px"android:id="@+id/CheckBox_Accept"android:layout_width="120pt"></CheckBox> <Buttonandroid:layout_height="wrap_content"android:layout_marginLeft="90px"android:id="@+id/Button_OK"android:text="确定"android:layout_width="90px"/></LinearLayout> 
AgreeTest.java
  
package com.hoocy;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.CheckBox;import android.widget.TextView;public class AgreeTest extends Activity {private TextView showAdvice,yourChoiceshow;private CheckBox iAccept;private Button ok;    @Override    public void onCreate(Bundle savedInstanceState) {      super.onCreate(savedInstanceState);      setContentView(R.layout.main);                showAdvice = (TextView) findViewById(R.id.TextView_Guide);      yourChoiceshow=(TextView) findViewById(R.id.TextView_youChoiceShow);      iAccept=(CheckBox) findViewById(R.id.CheckBox_Accept);      ok=(Button) findViewById(R.id.Button_OK);                CharSequence titleString = getString(R.string.allOK);                iAccept.setHint(titleString);      iAccept.setHintTextColor(Color.RED);      iAccept.setChecked(false);                ok.setEnabled(false);      iAccept.setOnClickListener(new CheckBox.OnClickListener(){public void onClick(View v) {if(iAccept.isChecked()){ok.setEnabled(true);yourChoiceshow.setText(R.string.accepte);}else{ok.setEnabled(false);yourChoiceshow.setText(R.string.Notaccept);}}      });      ok.setOnClickListener(new Button.OnClickListener(){public void onClick(View v) {showAdvice.setText(R.string.accepte);}      });    }} 
 
 
页: [1]
查看完整版本: android_学习练习2