2011-04-24 5 views
1

안녕하세요 이제 회 전자 사용 방법에 대한 몇 가지 예를 살펴 보았습니다. 그러나 내가 그 conent를 표시하지 않습니다 에뮬레이터에서 스피너를 시도 무엇이든 중요하지 않습니다 ... 이 내가 사용하는 코드입니다 :왜 Spinner에 내 항목이 들어 있지 않습니까?

public class NewBooking extends Activity { 

private static List<String> l = new ArrayList<String>(); 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.newbooking); 
    String[] items = new String[] {"One", "Two", "Three"}; 
    Spinner spinner = (Spinner) findViewById(R.id.cmbNewBookingType); 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_spinner_item, items); 
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    spinner.setAdapter(adapter); 
} 
} 

내가 문질러서 항목을 추가해야이 코드를 하나, 둘, 셋, 스피너 컨트롤에 있지만 컨트롤은 에뮬레이터에서 비어 있습니다 ...

어떤 아이디어가 잘못되었을 수 있습니까?

감사합니다.

+0

내가 게시 한 코드는 올바른 레이아웃 xml을 제공하는 3 개의 항목이있는 회 전자를 보여주는 나를 위해 예상대로 작동합니다. 레이아웃 xml은 어떤 모양입니까? –

답변

0

내가이 플랫폼에서 경험 한 모든 사람이 아니기 때문에, 무엇을 잘못했는지 확실하지 않습니다.

하지만

난 그냥 스피너를 구현하고, 이것은 내가 사용하는 코드입니다 - 유용 할 수 있습니다.

final Spinner spnrCategory = (Spinner) this.findViewById(R.id.spinnerCategory); 
    // The Spinner does not generate an interrupt for OnClick ... 
    // We use an adapter to set and access data in the Spinner 
    // The data to populate the Spinner is in the Strings resource file 
    // We have to define what the spinner looks like when closed and also when open!!! 
    ArrayAdapter<?> spinnerAdapter = ArrayAdapter.createFromResource(this,R.array.Categories, android.R.layout.simple_spinner_item); 
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    spnrCategory.setAdapter(spinnerAdapter); 
    spnrCategory.setSelection(0); // Default to the first category 
    strCategoryType = spnrCategory.getSelectedItem().toString(); 

그리고이 코드를 strings.xml 파일에 넣었습니다.

<string-array name="Categories">   
    <item>LIVE: Gardening</item> 
    <item>LIVE: Allotments</item> 
    <item>Other</item> 
</string-array> 

다음

는 '다음'부톤 섬은 그것은 나를 위해 작동
Button btnNext = (Button) this.findViewById(R.id.btnNext); 
    btnNext.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      strCategoryType = spnrCategory.getSelectedItem().toString(); 
      Intent intentNextActivity; 
      intentNextActivity = new Intent(SelCategoryActivity.this, ShowVideoActivity.class);    
      startActivity(intentNextActivity); 
      SelCategoryActivity.this.finish(); 
     } 
    }); 

을 클릭하면, 예를 들어, 회 전자의 데이터를 사용하는 당신

환호에 유용 희망합니다 ,

올리버

0

해결 된 내 문제. 나는 새로운 활동의로드를 이해하지 못했습니다. 모든 것이 새로운보기를 표시하는 방법을 변경 한 후에 작동합니다.

Intent intent = new Intent(this, NewBooking.class); 
startActivity(intent); 
관련 문제