<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="com.example.test.MainActivity"
tools:ignore="MergeRootFrame" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textViewSampleFrequency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sample_frequency" />
<EditText
android:id="@+id/editTextSamFre"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="@string/pleaseInputSamFre"
android:inputType="number" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/buttonSamFre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sample_frequency"
/>
</LinearLayout>
</LinearLayout>
package com.example.test;
import android.app.AlertDialog;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
private Button buttonSamFre;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 初始化当前所需要的控件
buttonSamFre = (Button)findViewById(R.id.buttonSamFre);
// 设置监听事件
buttonSamFre.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
System.out.println("asdf");
new AlertDialog.Builder(MainActivity.this)
.setTitle("标题")
.setMessage("简单消息框")
.setPositiveButton("确定", null)
.show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}