六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 45|回复: 0

android_学习练习2

[复制链接]

升级  10.67%

68

主题

68

主题

68

主题

举人

Rank: 3Rank: 3

积分
232
 楼主| 发表于 2013-1-15 02:49:05 | 显示全部楼层 |阅读模式
 
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: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"    ><TextView  android: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);}        });    }} 
 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表