2014-05-20 2 views
1

나는이 seekbar 및이 TextView에서 seekbar의 실제 진행 상황을 보여주고 싶습니다. 텍스트 뷰의 실제 XML :SeekBar에서 진도 설정

  <SeekBar 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/seekBar1" 
      android:layout_below="@+id/dimension_text"/> 

      <TextView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:text="@string/num_dimension" //where num_dimension is a number 
      android:id="@+id/textViewProgress"/> 

그리고 실제 자바 : 나는 SeekBar를 내 응용 프로그램에 탭 때마다

public class MainActivity extends ActionBarActivity { 
int p=0; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    final TextView t1=(TextView) findViewById(R.id.test); 
    final SeekBar sk=(SeekBar) findViewById(R.id.seekBar1); 
    final TextView textProgress = (TextView)findViewById(R.id.textViewProgress); 

    sk.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 
     @Override 
     public void onStopTrackingTouch(SeekBar seekBar) { 
// TODO Auto-generated method stub 
      if(p<12) 
      { 
       p=12; 
       sk.setProgress(p); 
      } 

     } 
     @Override 
     public void onStartTrackingTouch(SeekBar seekBar) { 
// TODO Auto-generated method stub 
     } 
     @Override 
     public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) { 
// TODO Auto-generated method stub 
      p=progress; 
      t1.setTextSize(p); 
      textProgress.setText(p); //this is the line that should do the work 
     } 
    }); 

가 힘을 폐쇄. 그래서 약간 혼란 스럽습니다. 내가 뭘 잘못하고 있니? 문자열로

05-20 17:59:04.141 29872-29872/com.myapplication2.app D/dalvikvm﹕ GC_FOR_ALLOC freed 424K, 14% free 10583K/12268K, paused 23ms, total 23ms 
05-20 17:59:04.171 29872-29872/com.myapplication2.app I/Xposed﹕ [IconThemer/Mod] [nexbit.moonshine.icons] Loading replacements for package com.myapplication2.app 
05-20 17:59:04.251 29872-29872/com.myapplication2.app D/dalvikvm﹕ GC_FOR_ALLOC freed 274K, 13% free 10804K/12348K, paused 19ms, total 19ms 
05-20 17:59:04.312 29872-29872/com.myapplication2.app I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I0404c4692afb8623f95c43aeb6d5e13ed4b30ddbDate: 11/06/13 
05-20 17:59:04.382 29872-29872/com.myapplication2.app D/OpenGLRenderer﹕ Enabling debug mode 0 
05-20 17:59:10.548 29872-29872/com.myapplication2.app W/ResourceType﹕ No package identifier when getting value for resource number 0x00000002 
05-20 17:59:10.548 29872-29872/com.myapplication2.app E/InputEventReceiver﹕ Exception dispatching input event. 
05-20 17:59:10.548 29872-29872/com.myapplication2.app D/AndroidRuntime﹕ Shutting down VM 
05-20 17:59:10.548 29872-29872/com.myapplication2.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41543ba8) 
05-20 17:59:10.558 29872-29872/com.myapplication2.app E/AndroidRuntime﹕ FATAL EXCEPTION: main 
    Process: com.myapplication2.app, PID: 29872 
    android.content.res.Resources$NotFoundException: String resource ID #0x2 
      at android.content.res.Resources.getText(Resources.java:244) 
      at android.content.res.XResources.getText(XResources.java:508) 
      at android.widget.TextView.setText(TextView.java:3888) 
      at com.myapplication2.app.MainActivity$2.onProgressChanged(MainActivity.java:77) 
      at android.widget.SeekBar.onProgressRefresh(SeekBar.java:91) 
      at android.widget.ProgressBar.doRefreshProgress(ProgressBar.java:655) 
      at android.widget.ProgressBar.refreshProgress(ProgressBar.java:667) 
      at android.widget.ProgressBar.setProgress(ProgressBar.java:714) 
      at android.widget.AbsSeekBar.trackTouchEvent(AbsSeekBar.java:451) 
      at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:379) 
      at android.view.View.dispatchTouchEvent(View.java:7706) 
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 
      at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) 
      at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959) 
      at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068) 
      at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515) 
      at android.app.Activity.dispatchTouchEvent(Activity.java:2458) 
      at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268) 
      at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016) 
      at android.view.View.dispatchPointerEvent(View.java:7886) 
      at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3954) 
      at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3833) 
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399) 
      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449) 
      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418) 
      at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525) 
      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426) 
      at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582) 
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399) 
      at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449) 
      at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418) 
      at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426) 
      at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399) 
      at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602) 
      at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582) 
      at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553) 
      at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5682) 
      at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) 
      at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 
      at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176) 
      at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5655) 
      at  android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5701) 
      at android.view.Choreographer$Ca 
+0

logcat을 게시 할 수 있습니까? – MJ93

+0

@ MJ93 여기에 간다 – Lampione

답변

1

캐스트 p :

는 로그 캣입니다.

당신은 실수로이 오버로드를 사용하고 있습니다 :

http://developer.android.com/reference/android/widget/TextView.html#setText(int)p과 동일한 ID (당신이 residp 전달하는)으로 문자열 리소스를 검색하려고하고, 그런이 없습니다

public final void setText (int resid) 

자원을 생성합니다.

public final void setText (CharSequence text) 

을 그리고 당신의 응용 프로그램이 충돌하지 않습니다

변경

textProgress.setText(p); 

textProgress.setText(Integer.toString(p)); 

에이 적절한 오버로드를 호출합니다.

Logcat을 사용하는 법을 배우십시오. 그렇지 않으면 어두운 데에서 벗어날 것입니다.

+0

고마워! 나는 아직도 자바에 익숙하지 않기 때문에 모든 것을 마음 속에 간직 할 것입니다. 나는 logcat에 관해 더 많이 공부할 것이다, 다시 당신에게 감사해라! :) – Lampione

+0

@ Lampione 아무 문제없이, 우리 모두는 어딘가에서 시작해야합니다. –

관련 문제