您好朋友,我在我的项目中使用seekbarpefernce库“ com.yokkomi:seekbar-preference:1.0”,问题是当我尝试从此seekbar中获取价值时,它总是给我默认值,该值是我在从sharedperfernce获取价值时设置的,请帮忙我如何在其更改后如何获取seekbar值是我的代码在扬声器方法中获取sharedperfe值,请在我的代码中的扬声器方法下面查看!
库链接在这里:https://github.com/ghkim3221/SeekBarPreference
我的表现圣礼:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreference
android:defaultValue="false"
android:key="autospeak"
android:title="Auto Speak"
android:summary="Turn on/off auto verse read"/>
<com.yokkomi.commons.preference.seekbar.SeekBarPreference
android:defaultValue="11"
android:dialogTitle="Verse Reading Speed"
android:key="versespeed"
android:summary="Adjust verse reading speed"
android:title="Verse Speed"
app:explain="Drag it left or right"
app:maxValue="20"
app:padding="3"/>
<com.yokkomi.commons.preference.seekbar.SeekBarPreference
android:defaultValue="8"
android:dialogTitle="Voice Picth Settings"
android:key="voicepitch"
android:summary="Adjust verse reading pitch"
android:title="Voice Pitch"
app:explain="Drag it left or right"
app:maxValue="20"
app:padding="3"/>
<SwitchPreference
android:defaultValue="false"
android:key="switchmode"
android:title="Turn on Dark Mode"
android:summary="Reading in night mode"/>
package bible.swordof.God;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Handler;
import android.speech.tts.TextToSpeech;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.yokkomi.commons.preference.seekbar.SeekBarPreference;
import java.util.ArrayList;
import java.util.Locale;
import es.dmoral.toasty.Toasty;
public class ALLVERSE extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener,TextToSpeech.OnInitListener {
private ListView mylistview;
private ArrayList<String>versenumber;
private ArrayList<String>verselist;
private ArrayList<String>id;
private ArrayList<String>refernce;
private DatabaseHelper mDBHelper;
private SQLiteDatabase mDb;
private int booknumber;
private int chapternumber;
private String bookname;
public int versepos;
private TextView booknametitle;
TextToSpeech textToSpeech;
private static SharedPreferences sharedPreferences;
int result;
private static final int MY_DATA_CHECK_CODE = 0;
private FullverseAdopter fullverseAdopter;
RelativeLayout linearLayout;
@Override
protected void onDestroy() {
if (textToSpeech!= null) {
textToSpeech.stop();
textToSpeech.shutdown();
}
super.onDestroy();
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_allverse);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
booknametitle = findViewById(R.id.bookname);
linearLayout=findViewById(R.id.color);
final Intent mIntent = getIntent();
booknumber = mIntent.getIntExtra("Boooknumber", 0);
chapternumber = mIntent.getIntExtra("Chapternumber", 0);
bookname = mIntent.getStringExtra("Bookname");
versepos=mIntent.getIntExtra("versenumber",1);
SharedPreferences sharedPreferences=this.getSharedPreferences("DATA",MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putInt("versenumber",versepos);
editor.commit();
booknametitle.setText(bookname.toString() + " " + chapternumber);
setSupportActionBar(toolbar);
toolbar.setTitle("ALL VERSE");
textToSpeech=new TextToSpeech(this,this);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
setData();
mylistview = findViewById(R.id.mylistview);
BaseAdapter baseAdapter = new BaseAdopter(this, versenumber, id, verselist, refernce);
mylistview.setAdapter(baseAdapter);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if(DefaultSettings.autospeak(ALLVERSE.this)){
speakOut(verselist.get(versepos-1));
}
//speak after 1000ms
}
}, 1000);
mylistview.setSelection(Integer.valueOf(versepos)-1);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {
onBackPressed();
}
return super.onOptionsItemSelected(item);
}
private void setData() {
versenumber=new ArrayList<>();
verselist=new ArrayList<>();
refernce=new ArrayList<>();
id=new ArrayList<>();
mDBHelper = new DatabaseHelper(this);
mDb = mDBHelper.getReadableDatabase();
Cursor cursor = mDb.rawQuery("SELECT id, v, t from t_kjv where b="+booknumber+" AND c="+chapternumber+";", new String[]{});
if(cursor!=null && cursor.getCount() > 0)
{ if (cursor.moveToFirst())
{
do {
id.add(cursor.getString(0));
versenumber.add(cursor.getString(1));
verselist.add(cursor.getString(2));
refernce.add(bookname+" "+chapternumber);
}
while (cursor.moveToNext());
}
}
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment fragment;
int id = item.getItemId();
if (id == R.id.home) {
Intent intent=new Intent(this,MainActivity.class);
startActivity(intent);
} else if (id == R.id.favoruite)
{ Intent intent=new Intent(this,Favourite.class);
startActivity(intent);
} else if (id == R.id.setting) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
//这是getingperfernces始终返回11,我将其设置为默认值
private void speakOut(String text) {
sharedPreferences=getSharedPreferences("versespeed",MODE_PRIVATE);
float speed=(float)sharedPreferences.getInt("versespeed",11)/50;
if(speed<0.1)speed=0.1f;
/* float pitch=(float)sharedPreferences.getInt("voicepitch",11)/50;
if(pitch<0.1)pitch=0.1f;
textToSpeech.setPitch(pitch);*/
textToSpeech.setSpeechRate(speed);
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null);
Toast.makeText(this, ""+speed, Toast.LENGTH_SHORT).show();
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.US);
// tts.setPitch(5); // set pitch level
// tts.setSpeechRate(2); // set speech speed rate
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "Language is not supported");
} else {
}
} else {
Log.e("TTS", "Initilization Failed");
}
}
}
最佳答案
我是SeekBarPreference的开发人员。
SeekBarPreference当前不起作用,无法维护。
真的很抱歉,您最好再找一个图书馆。