2012-09-05 4 views

답변

2

일부 메서드 내에서 전체 코드를 이동해야합니다. 클래스의 메서드 외부에서 코드를 실행할 수 없습니다.

전체 코드를 Oncreate 내부로 옮기는 것이 좋습니다.

public class SpinnerBuilding extends Activity { 
public void onCreate(Bundle b){ 

super.onCreate(b); 
setContentView(R.id.layout); 
Spinner spinner = (Spinner) findViewById(R.id.building); 

// Create an ArrayAdapter using the string array and a default spinner layout 
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, 
     R.array.buildings_array, android.R.layout.simple_spinner_item); 

// Specify the layout to use when the list of choices appears 
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

// Apply the adapter to the spinner 
spinner.setAdapter(adapter); 
} 
} 
+1

오른쪽 ... 잊어 버렸습니다 ... 대단합니다. 그래서 이것을 잊어 버린 다른 코드에 고정되었습니다 ... – JHoo

+0

작동하지 않는 것 같습니다 ... 지금 구문 오류가 없습니다. 그러나 회 전자는 전혀 표시되지 않습니다. 나는 왜 ..? – JHoo

+0

아, 지금 받았어. 고마워! – JHoo

1

클래스의 어딘가에이 작업을 수행 할 수 없습니다. 거의 모든 것을 onCreate() 메서드에 넣는 것이 좋습니다.

0

Oncreate() 내부에 어댑터를 설정해야합니다. 또한 setContentView (R.layout.yourlayout)를 사용하십시오.

관련 문제