<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<EditText
android:id="@+id/et1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="버튼 1"
android:textColor="#0000ff"
android:onClick="onClick" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="버튼 2" />
</LinearLayout>
package com.example.testex03;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
InputMethodManager imm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
Button btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// alert 창
EditText et1 = (EditText)findViewById(R.id.et1);
String msg = et1.getText().toString();
Toast.makeText(MainActivity.this,msg, Toast.LENGTH_SHORT).show();
//외부객체명
imm.hideSoftInputFromWindow(et1.getWindowToken(), 0);
}
});
}
@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;
}
public void onClick(View v){
Toast.makeText(this, "버튼 클릭", Toast.LENGTH_SHORT).show();
}
}
'Android' 카테고리의 다른 글
RelativeLayout (0) | 2013.03.27 |
---|---|
리니어 레이아웃 - 베이스정렬(baselineAligned) (0) | 2013.03.26 |
이미지뷰(imageView) 실습 (0) | 2013.03.26 |
텍스트뷰(TextView) 실습 (0) | 2013.03.26 |
안드로이드 에뮬레이터(AVD)에서 한글자판 사용하기 (0) | 2013.03.25 |