2011-11-12 2 views
0

다음은 기본적인 문제라고 생각합니다. 내가 팽창에 AlertDialog에 통합 한 http://www.quietlycoding.com/?p=5&cpage=1#comment-10645번호 선택기의 기능 호출 방법

: 안드로이드 SDK가 제공하는 것도이 없기 때문에

나는이 번호 선택 도구를 사용하여. 여기 팽창 레이아웃 :

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
> 
    <com.example.NumberPicker 
     android:padding="10dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

이 난에 AlertDialog에 버튼을 추가했습니다. 클릭하면 숫자 선택 도구의 현재 값을 가져오고 싶습니다.

수 선택기 클래스는 기능을 제공합니다 :

public static int getCurrent() { 
     return mCurrent; 
    } 

문제는 내가 그것을 호출하는 방법을 인식하지 오전입니다. 나는 수업의 대상이 없다. com.example.NumberPicker.getCurrent()를 통해 호출하는 경우 정적으로 선언해야하며 일부 부정적인 부작용이 있습니다.

다른 사람이 getCurrent() 함수를 호출하기 위해 피커 클래스의 객체를 얻는 방법을 알고 있습니까?

나는 새 객체를 만드는 것이 옳지 않다라고 생각한다. 왜냐하면 나는 내 alerdialog에서 실행중인 객체로부터 함수를 호출하기를 원하기 때문이다.

편집 :

NumberPicker np = new NumberPicker(MainScreen.this); 
Log.v("TEST", "" + np.getCurrent()); 

이 편집 2 0

항상 저를 제공합니다 : 내가 안드로이드 ID 추가 : 내가 할

<com.example.NumberPicker 
     android:id="@+id/numberPicker" 
     android:padding="10dp" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

나는 내 코드를 내가 기대 한대로 다음 :

LayoutInflater factory = LayoutInflater.from(this); 
      final View textEntryView = factory.inflate(
        R.layout.backfall_layout, null); 



      new AlertDialog.Builder(MainScreen.this) 
        .setTitle(this.getString(R.string.relapse)) 
        .setView(textEntryView) 
        .setPositiveButton("OK", 
          new DialogInterface.OnClickListener() { 
           public void onClick(DialogInterface dialog, 
             int whichButton) { 
           NumberPicker np = (NumberPicker) findViewById(R.id.numberPicker); 

           Log.v("TEST", "" + np.getCurrent()); 

-- 

하지만 지금 내 앱 버튼을 누른 후 충돌 ..

편집 3 :

그것을 해결 : 나는 누군가가 내가의 목적을 얼마나 알고 있나요

NumberPicker np = (NumberPicker) textEntryView.findViewById(R.id.cigarettesPicker); 
      np.setCurrent(1); 
+0

내장 된 NumberPicker를 사용하는 대신이 UI 라이브러리 (http://code.google.com/p/android-wheel/)를 살펴 보시기 바랍니다. – anticafe

답변

2

를 호출해야 피커 클래스 getCurrent() 함수를 호출하기 위해?

  1. 는 레이아웃 XML에 NumberPicker 요소에 android:id 값을 추가합니다.
  2. 당신이 1 단계에서 제공되는 ID를 전달하고, NumberPicker로 결과를 캐스팅, 팽창 레이아웃에 findViewById()를 호출하여 AlertDialog의 레이아웃을 팽창

    .

+0

Thx. 나는 이것이 올바른 방법이라고 생각한다.하지만 내 응용 프로그램이 충돌합니다. 위의 게시물에 새 코드를 추가합니다. – tobias