여러가지 버튼링크를 만들기
Posted by Albert 4802Day 17Hour 50Min ago [2012-02-25]
간단한 버튼링크들을 만들어 보았습니다.
1번: 버튼을클릭시 작은 메세지창이 떳다 사라지는 효과
2번: 특정 사이트로 링크를 시켜주는 링크
3번: 클릭시 자동적으로 전화걸기 화면으로 넘겨주는 링크입니다. ^^
실행기본메뉴
1. res/layout/main.xml (모바일 디자인 페이지 소스)
==============================================================================
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:id="@+id/startBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
android:id="@+id/start02Btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="네이버 접속하기" />
android:id="@+id/start03Btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="전화걸기" />
1번째 버튼 클릭시 화면
2번째 네이버가기버튼 클릭시 화면
3번째 전화걸기버튼 클릭시 화면 ^^
2. 클릭시 발생되는 이벤트 java파일소스
==============================================================================
package org.androidtown.hello;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class HellowActivity extends Activity {
protected static final Uri ACTION_VIEW = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// button1 -> make program link ^^ show a message box
Button startBtn = (Button) findViewById(R.id.startBtn);
startBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "시작버튼이 눌렸어요", 1000).show();
Intent myIntent = new Intent(getApplicationContext(), NewActivity.class);
startActivity(myIntent);
}
});
// button -> make web link
Button start02Btn = (Button) findViewById(R.id.start02Btn);
start02Btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://m.naver.com"));
startActivity(myIntent);
}
});
// button -> make call phone btn
Button start03Btn = (Button) findViewById(R.id.start03Btn);
start03Btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent myIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("tel:/010-8721-6894"));
startActivity(myIntent);
}
});
}
}