마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

앱 위젯을 만드려고 하는데 조금만 도움을 주세요ㅠㅠ

0 추천
위젯을 만드려고 하는데 책을 봐도 뭔말인지...

버튼을 두개 만들면 하나만 실행 되더라구여

위젯을 3개 만들건데 두개는 전화거는 위젯 예를들면 114나 112로 통화되는 위젯이고

다른 하나는 제가만들어 놓은 페이지로 이동하는 위젯을 만드려고 하는데

도와주세요ㅠㅠ
an드로id (360 포인트) 님이 2015년 1월 2일 질문

1개의 답변

0 추천
 
채택된 답변

// 우선 메인 화면 디자인

res/layout/wiget3.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" 
    >
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="call 114" />
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="call 112" />
    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Custom" 
        />
</LinearLayout>

// 버튼을 클릭했을 때 

private static final String TAG = "Wiget3";
Button button1, button2, button3;
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wiget3);
 
button1 = (Button)findViewById(R.id.button1) ;
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
call("tel:114") ;
}
});
 
button2 = (Button)findViewById(R.id.button2) ;
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
call("tel:112") ;
}
});
 
 
button3 = (Button)findViewById(R.id.button3) ;
button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
doCustom() ;
}
});
}
 
public void call(String phone) {
   try {
    Log.d(TAG, phone+" 호출입니다.") ;
       Intent callIntent = new Intent(Intent.ACTION_CALL);
       callIntent.setData(Uri.parse(phone));
       startActivity(callIntent);
   } catch (ActivityNotFoundException e) {
        Log.e("myphone dialer", "Call failed", e);
   }
}
 
private void doCustom() {
Log.d(TAG, "사용자가 호출입니다.") ;
Toast.makeText(getBaseContext(), "사용자 호출입니다.", Toast.LENGTH_LONG).show() ;
}
 
//AndroidManifest.xml 추가(전화걸기)
 
<uses-permission android:name="android.permission.CALL_PHONE
 
익명사용자 님이 2015년 1월 2일 답변
an드로id님이 2015년 1월 2일 채택됨
이 소스를 제가 만든 어플에 넣어서 실행을 시켜봤는데 이 소스가 다른걸 다 먹어버리더라고요..제가 만든 페이지들을 말이죠...이건 어떡하죠??
...