2014-07-25 4 views
0

클릭 가능한 레이아웃에 TextView가 포함 된 활동을하고 있습니다. onClick 메서드는 TextView의 가능한 값 (3 가지 가능한 값 (0), (1), (2))이 포함 된 경고 대화 상자를 엽니 다. 값을 가져 오려면 AlertDialog를 사용해야하며 Spinner는 작동하지 않습니다. int BUSselection은 프로그램 시작시 -1로 선언됩니다.TextView setText AlertDialog가 늦음

public void showStartingDialog(){ 
     DialogFragment dialog = new StartingDialogFragment(); 
     dialog.show(getFragmentManager(), "StartingDialogFragment"); 
    } 
    public void onBUSDialogSelect(DialogFragment dialog, int which) 
    {BUSselection = which;} 

public void changeStarting(View v) //OnClick method 
{ 
    showStartingDialog(); 
    TextView basic = (TextView)findViewById(R.id.startingBox); 
    if(BUSselection==0) 
    { 
     basic.setText("0"); 
    } 
    else if (BUSselection ==1) 
    { 
     basic.setText("1"); 
    } 
    else if (BUSselection ==2) 
    { 
     basic.setText("2"); 
    } 
    else 
    { 

    } 
} 

기본적으로이 프로그램은 (위치 2에서, 위치 1에서 위치 0 "0", "2", "1")을에 AlertDialog리스트의 선택 옵션을 가지고에 그 값을 넣어하도록되어 TextView. 그러나, 내 문제는 내가 위치 1을 선택하면, 내가 (경고 대화 상자가 다시 나타납니다) 두 번째 시간을 클릭하기 전까지는 TextView에 1이 나타나지 않는다는 것입니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

코드를 더 이상 보지 않고도 invalidate()를 호출하여 TextView를 업데이트하도록 강요 할 수 있습니다. 예를 들어

:

TextView basic = (TextView) v.findViewById(R.id.startingBox); 
. 
. 
basic.setText("1"); 
. 
. 
v.invalidate(); // forces view to refresh its components 

참고, 그 V는 텍스트 뷰를 포함하는 뷰를 참조해야합니다.

0

대화 상자가 끝나기 전에 showStartingDialog()이 반환한다는 문제가 있다고 생각합니다. 전화를받은 후 회선은 onBUSDialogSelect() 방법으로 지정해야합니다. 이 같은

뭔가 :

public void showStartingDialog() { 
    DialogFragment dialog = new StartingDialogFragment(); 
    dialog.show(getFragmentManager(), "StartingDialogFragment"); 
} 

public void onBUSDialogSelect(DialogFragment dialog, int which) { 
    BUSselection = which; 
    TextView basic = (TextView)findViewById(R.id.startingBox); 
    if(BUSselection==0) { 
     basic.setText("0"); 
    } else if (BUSselection ==1) { 
     basic.setText("1"); 
    } else if (BUSselection ==2) { 
     basic.setText("2"); 
    } else { 

    } 
} 

// OnClick method 
public void changeStarting(View v) { 
    showStartingDialog(); 
}