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

예제 만지고 있는 이제 사흘 된 초보입니다. [closed]

0 추천

안녕하세요

이제 안드로이드 코드를 만진지 사흘 정도 된 꼬꼬마입니다.

질문 양식이나 방법이 잘못되었다면 지적 부탁드립니다.

 

요새 북스홀릭에서 나온 안드로이드 프로그래밍이라는 책을 보고

예제를 연습하고 있는데요.

radiobutton 과 checkbox를 통해 피자를 주문하는 예제입니다.

 

그런데 책과 똑같이 쳤는데도 오류는 없이 run이 안되어서

밤새 낑낑댔는데 어디를 고쳐야할지 몰라 질문드립니다 ㅠㅠ 

 

src 의 pizzaActivity.java 코드는 아래랑 같구요

 

package com.example.pizzaorder;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class PizzaActivity extends AppCompatActivity {

RadioGroup radiogroup;
RadioButton radioPizza;
CheckBox checkKetchup;
CheckBox checkPickle;
CheckBox checkSource;
Button button;
TextView text;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pizza);

text = (TextView)findViewById(R.id.text);
checkKetchup = (CheckBox)findViewById(R.id.cb_ketchup);
checkPickle = (CheckBox)findViewById(R.id.cb_pickle);
checkSource = (CheckBox)findViewById(R.id.cb_source);
radiogroup = (RadioGroup)findViewById(R.id.radiogroup);
button = (Button)findViewById(R.id.button);

radiogroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
radioPizza = (RadioButton)findViewById(checkedId);
}
});

button.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub
String strPizza ="";
String strOption ="";

if(radioPizza != null){
strPizza = radioPizza.getText().toString()+"를 주문하셨습니다\n"; 
if(checkKetchup.isChecked()){
strOption += checkKetchup.getText();
}
if(checkPickle.isChecked()){
strOption += checkPickle.getText();
}
if(checkSource.isChecked()){
strOption += checkSource.getText();
}
text.setText(strPizza+strOption);
}
else {
text.setText("피자를 선택해 주세요");
}
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pizza, 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);
}
}

 

layout 의 activity_pizza.xml은 아래와 같습니다.
 
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    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="com.example.pizzaorder.PizzaActivity" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="피자 종류를 선택해 주세요."
        android:textSize="20sp"
        android:background="#666666"/>
    
    <RadoiGroup
        android:id="@+id/radiogroup"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        
        <RadioButton
            android:id="@+id/rb_combination"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="콤비네이션 피자" />
        
        <RadioButton
            android:id="@+id/rb_cheese"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="치즈 피자" />
        
        <RadioButton
            android:id="@+id/rb_bulgogi"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="불고기 피자" />
        
    </RadoiGroup>
    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="옵션을 선택해 주세요"
        android:textSize="20sp"
        android:background="#666666"/>
    
    <CheckBox
        android:id="@+id/cb_ketchup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="케첩 추가" />
    
    <CheckBox
        android:id="@+id/cb_pickle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="피클 추가" />
    
    <CheckBox
        android:id="@+id/cb_source"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="소스 추가" />
    
    <Button 
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="클릭해주세요" />"
    
    <TextView 
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

</RelativeLayout>

 

 
 
이미지도 같이 첨부합니다결과화면project explorer

 

질문을 종료한 이유: 해결했습니다!! 두분 다 감사합니다
익명사용자 님이 2015년 7월 10일 질문
2015년 7월 10일 closed
답변 덕분에 해결한거면 질문을 종료하지 말고 도움 준 분의 답변을 채택해야 합니다.

2개의 답변

0 추천
androidManifest.xml 알맞게 고치셨나요
JSGames (140 포인트) 님이 2015년 7월 10일 답변
그건 아직 책에서 안나왔는데 검색해보고 확인해보겠습니다!!
0 추천
RadoiGroup  이부분 오타나셨네요..

RadioGroup 이렇게 바꿔주세요ㅋ
지나가던닝겐 님이 2015년 7월 10일 답변
감사합니다!!

오탈자를 문제일거라고 생각해서 몇번이나 확인했는데

제 눈에는 안 보였네요 ㅠㅠ

확인해주셔서 감사합니다!!
...