[英]I want to implement SeekBar in android ,But when i run the below program my emulator shows error that “Unfortunately SeekBar has been stopped”
When I change the seekbar in spite of showing the value it says "unfortunately SeekBarActivity has been stopped" 当我更改搜索栏时尽管显示了该值,但显示“不幸的是,SeekBarActivity已停止”
activity_main.xml file: activity_main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<SeekBar
android:id="@+id/sb"
android:layout_width="match_parent"
android:layout_height="63dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="178dp"
tools:layout_editor_absoluteX="99dp"
tools:layout_editor_absoluteY="201dp" />
<TextView
android:id="@+id/tv"
android:layout_width="326dp"
android:layout_height="64dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/sb"
android:layout_marginStart="14dp"
android:text=""
tools:ignore="UnknownId"
tools:layout_editor_absoluteX="99dp"
tools:layout_editor_absoluteY="219dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="14dp" />
<RatingBar
android:id="@+id/rb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="53dp" />
</RelativeLayout>
MainActivity.java file MainActivity.java文件
package com.example.mypc.seekbarapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
TextView tv;
SeekBar sb;
RatingBar rb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView) findViewById(R.id.tv);
sb=(SeekBar)findViewById(R.id.sb);
rb=(RatingBar)findViewById(R.id.rb);
sb.setMax(100);
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int pro=0;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
pro=progress;
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
tv.setText(pro);
//
Toast.makeText(MainActivity.this,pro,Toast.LENGTH_LONG).show();
}
});
rb.setOnRatingBarChangeListener(new
RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(MainActivity.this,
String.valueOf(rating),Toast.LENGTH_LONG)
.show();
}
});
}
}
my Stack trace: 我的堆栈跟踪:
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:122)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller
.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
09-04 17:37:04.097 2773-2773/? I/Process: Sending signal. PID: 2773 SIG:
9
Where I am wrong?? 我哪里错了? Any help will b appreciated, thanks in advance.
任何帮助将不胜感激,在此先感谢。 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“” “”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”“”
you are calling tv.setText(pro);
您正在呼叫
tv.setText(pro);
when pro is an int value int argument in setText is an string id such as R.string.some_id
when you call it with an int and Android can not find string resource with an id equals to pro value you get Resource not found exception. 如果pro是int值,则setText中的int参数是字符串ID(例如
R.string.some_id
当您使用int调用它时,Android无法找到ID等于pro值的字符串资源,则会出现Resource not found异常。 you should change it to: 您应该将其更改为:
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int pro=0;
String proStr = "";
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
pro=progress;
proStr = String.valueOf(pro);// convert int to String
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
tv.setText(proStr); // use String instead of int
Toast.makeText(MainActivity.this, proStr, Toast.LENGTH_LONG).show(); // use String instead of int
}
});
My guess is that the mediastream isn't keeping up with the position of the seeker. 我的猜测是媒体流跟不上搜寻者的位置。
When you update the seeker, make sure the content you're trying to seek to is already in queue. 更新搜索程序时,请确保您要搜索的内容已在队列中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.