background image

android:layout_width

="wrap_content" 

android:layout_height

="wrap_con 

tent" 

android:text

="@string/go"> 

<

requestFocus 

/> 

</

Button

这里有两个地方要注意:id=@+id/go,这表示需要一个唯一的 UID 来作为 Button 的 ID, 

它的引用名是 go。还有一个是 android:text=@string/go 表示这个按钮的文本不是直接 

写有 main.xml 里了,而是来源于另一个资源描述文件 strings.xml 里,本例中的 

strings.xml 如下: 

<?

xml version="1.0" encoding="utf-8"

?> 

<

resources

<

string 

name

="app_name">

helloTwo

</

string

<

string 

name

="tit_dialog">

提示

</

string

<

string 

name

="msg_dialog">

你好,中国

</

string

<

string 

name

="ok_dialog">

确定

</

string

<

string 

name

="go">

浏览

</

string

</

resources

然后,在代码里(onCreate 函数中)我们加上以下代码(简单起见,用了嵌套类): 

Button btn = (Button)findViewById(R.id.go); 

btn.setOnClickListener

(

new 

View.OnClickListener() 

public void 

onClick(View v) 

EditText edt=(EditText)helloTwo.

this

.findViewById(R.id.edt);