一·
<span style="font-size:18px;"><strong>二·</strong></span>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg"
>
<EditText
android:id="@+id/etName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:drawableLeft="@drawable/name"
android:layout_marginTop="94dp"
android:background="@android:drawable/edit_text"
android:ems="10"
android:hint="@string/etNamePrompt">
<requestFocus />
</EditText>
<span style="font-size:18px;"><strong>三·</strong></span>
<Button
android:id="@+id/btnClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/btnClick" />
</RelativeLayout>
<pre name="code" class="java">package com.text.hellolili;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity
{
private Button btnClick;
private EditText etName;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClick=(Button) findViewById(R.id.btnClick);
btnClick.setOnClickListener(new ClickHandler());
etName=(EditText)findViewById(R.id.etName);
}
class ClickHandler implements OnClickListener
{
public void onClick(View view)
{
String name=etName.getText().toString();
Toast.makeText(MainActivity.this,"你好!"+name,Toast.LENGTH_LONG)
.show();
}
}
}
四·
在运行时,出现了unfortunately,hellolili stoped!经查找,是因为.java和.xml没有重建。然后就重头又开始了一遍,运行正常。