我正在开发一个语言词典应用程序.我将喜爱的单词保存到Preference中.XML文件中的收藏夹内容如下所示:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="history">
dict_name::160170::hi,dict_name::157140::he-man,dict_name::184774::jet,dict_name::34527::black
</string>
<string name="waitingTime">
0
</string>
<boolean name="saveFavourite" value="true" />
<string name="defaultDictionary">
dict_name
</string>
<string name="favourite">
dict_name::149271::go,dict_name::25481::back,dict_name::184774::jet
</string>
<boolean name="saveHistory" value="true" />
</map>
Run Code Online (Sandbox Code Playgroud)
我使用以下代码将收藏内容加载到webview中:
public class User extends Activity {
private static final String FAVOURITE_TAG = "[MyDict - FavouriteView] ";
private static final String CONTENT_TAG = null;
private ListView mLSTFavourite = null;
private ArrayList<String> lstDict = null;
private ArrayList<Integer> lstId = null;
private ArrayList<String> mWordFavourite = null;
private ArrayAdapter<String> aptList = …Run Code Online (Sandbox Code Playgroud) 我正在开发一个字典应用程序.在我的应用程序中,我假设用户想要保存喜欢的单词.我决定使用SharedPreferences来保存这些值(我知道SQLite和文件更好但我坚持使用"SharedPreferences",所以继续使用它).
以下是我的代码:
@Override
public void onClick(View v) {
SharedPreferences faves = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
{
SharedPreferences.Editor editor = faves.edit();
editor.putString("favourite", mSelectedDB + "::" + mCurrentWordId + "::" + mCurrentWord + ",");
editor.commit();
}
Log.i(CONTENT_TAG,"Favourite saved!");
Toast toast = Toast.makeText(ContentView.this, R.string.messageWordAddedToFarvourite, Toast.LENGTH_SHORT);
toast.show();
}
Run Code Online (Sandbox Code Playgroud)
问题是它不会保留多个最喜欢的单词.我的意思是只保存了一个最喜欢的单词,当添加新单词时,前一个单词被删除.
那么,如何编辑上面的代码以便解决这个问题呢?
你们有帮助吗?非常感谢你.
这是一个我无法回答的简单问题.
我在Excel中有两列这样的列:
Col1 Col2
A C
B I
C E
D D
E A
F F
G B
H
I
Run Code Online (Sandbox Code Playgroud)
我想对两列进行排序,以便相同的值在两列中的相同行上对齐,例如:
Col1 Col2
A A
B B
C C
D D
E E
F F
G
H
I I
K
Run Code Online (Sandbox Code Playgroud)
到目前为止,我已经尝试了以下VBA代码:
Sub HighlightDups()
Dim i, LastRowA, LastRowB
LastRowA = Range("A" & Rows.Count).End(xlUp).Row
LastRowB = Range("B" & Rows.Count).End(xlUp).Row
Columns("A:A").Interior.ColorIndex = xlNone
Columns("B:B").Interior.ColorIndex = xlNone
For i = 1 To LastRowA
If Application.CountIf(Range("B:B"), Cells(i, "A")) > 0 Then
Cells(i, "A").Interior.ColorIndex …Run Code Online (Sandbox Code Playgroud) 我已经能够改变活动背景的颜色(参见这篇文章).现在要求对背景图像做同样的事情.我的意思是我可以单击一个按钮,选择一个选项并将当前活动背景图像更改为新的.
这是我做的:
private SharedPreferences prefs;
private static final String SELECTED_ITEM = "SelectedItem";
private Editor sharedPrefEditor;
btnchangeColor = (ImageButton) findViewById(R.id.btnchangeColor);
btnchangeColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final CharSequence[] items={getString(R.string.default),getString(R.string.pix1), getString(R.string.pix2))};
AlertDialog.Builder builder = new AlertDialog.Builder(
ContentView.this);
builder.setTitle((getResources().getString(R.string.color_switch)));
builder.setPositiveButton((R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setSingleChoiceItems(items, getSelectedItem(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
wvContent = (WebView) findViewById(R.id.wvContent);
int bg_color=0;
if(getString(R.string.default).equals(items[which]))
{
wvContent.setBackgroundColor(0);
BitmapDrawable bg = …Run Code Online (Sandbox Code Playgroud) 我的 85MB 大小的 SQLite db 文件使用 XZ 格式压缩,其大小已减小到 16MB。我使用以下代码(以及XZ 为 Java提供的 JAR )在 Android Jelly Bean 中解压它:
try {
FileInputStream fin = new FileInputStream(path + "myFile.xz");
BufferedInputStream in = new BufferedInputStream(fin);
FileOutputStream out = new FileOutputStream(des + "myDecompressed");
XZInputStream xzIn = new XZInputStream(in);
final byte[] buffer = new byte[8192];
int n = 0;
while (-1 != (n = xzIn.read(buffer))) {
out.write(buffer, 0, n);
}
out.close();
xzIn.close();
}
catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
Run Code Online (Sandbox Code Playgroud)
解压成功,但需要两分钟多的时间才能完成。我认为这很长,因为压缩文件只有 16MB,未压缩文件只有 85MB。
我想知道我是否对代码做错了什么,或者有什么方法可以加快这个解压过程。
编辑编码:
我正在为Android开发一个字典应用程序.我一直在成功地让应用程序发出每个单词的意思.这是代码:
btnPronounce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Log.i(MAIN_TAG,"Start pronounciation ...");
btnPronounce.setEnabled(false);
String currentWord = edWord.getText().toString().toLowerCase();
try {
ZipFile zip = new ZipFile("/sdcard/app_folder/sound/zip_test.zip");
ZipEntry entry = zip.getEntry(currentWord);
if (entry != null) {
InputStream in = zip.getInputStream(entry);
// see Note #3.
File tempFile = File.createTempFile("_AUDIO_", ".wav");
FileOutputStream out = new FileOutputStream(tempFile);
IOUtils.copy(in, out);
// do something with tempFile (like play it)
File f = tempFile;
try {
if (f.exists())
{
Log.i(MAIN_TAG,"Audio file found!"); …Run Code Online (Sandbox Code Playgroud) 我想在我的Android应用程序中嵌入自定义字体.我不使用的TextView所以这样的教程为这一个(如何使用与TextView的自定义字体)没有帮助.
在我的例子中,内容来自SQLite数据库,并使用WebView显示在屏幕上.我既不使用捆绑的HTML文件,所以本教程(如何使用WebView自定义字体)也无法解决我的问题.
FIY,这是我的代码:
public void initWebview()
{
WebSettings settings = wvContent.getSettings();
settings.setDefaultTextEncodingName("utf-8");
setContentView(R.layout.content);
wvContent = (WebView) findViewById(R.id.wvContent);
wvContent.setBackgroundColor(Color.argb(250, 250, 250, 250));
wvContent.getSettings().setSupportZoom(true);
wvContent.getSettings().setBuiltInZoomControls(true);
wvContent.setInitialScale(100);
wvContent.setWebViewClient(new WebViewClient()
{
public void onPageFinished(WebView view, String url)
{
if (pd != null)
{
pd.dismiss();
pd = null;
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Log.i(CONTENT_TAG,"WebView link clicked; url = " + url);
try
{
String arrUrlPart[] = url.split("://");
if (arrUrlPart[0].equals("entry"))
{
String content = getContentByWord(arrUrlPart[1]);
showContent(content);
} …Run Code Online (Sandbox Code Playgroud) 我想使用正则表达式来查找两个标签之间的内容,如下所示:
<br />@ This is the content.</li>
Run Code Online (Sandbox Code Playgroud)
到目前为止,我一直在使用:
<br />@(.*?)</li>
Run Code Online (Sandbox Code Playgroud)
内容有时包含<li>标签,这不是我想要的.所以现在我想修改我的搜索,例如match <br />@(.*?)</li>不包含<li> tag.
然后我尝试:<br />@([^<li>].*?)</li>,但这仍包括<li>在搜索中.
你能给我一点帮助吗?谢谢.(注意,我使用TextWrangler)
我申请文本到语音到我的应用程序(如图所示的程序在这里).它在大多数设备上完美运行.但在某些设备中LG Optimus G, GK, L3 II and Sky IM-A800S,应用程序活动意外停止,并出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.appname/com.myapp.appname.ContentView}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.tts.engine.CHECK_TTS_DATA }
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4827)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.speech.tts.engine.CHECK_TTS_DATA }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1568)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1439)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivityForResult(Activity.java:3312)
at android.support.v4.app.FragmentActivity.startActivityForResult(Unknown Source)
at viettien.kadict.ContentView.onCreate(Unknown …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Java工具来将StarDict数据库转换为SQLite数据库,以便与Android Dictionary应用程序一起使用.但是我收到以下错误:
java.sql.SQLException: near "-": syntax error at
org.sqlite.DB.throwex(DB.java:288) at
org.sqlite.NativeDB.prepare(Native Method) at
org.sqlite.DB.prepare(DB.java:114) at
org.sqlite.Stmt.executeUpdate(Stmt.java:102) at
com.trivisionsc.ConvertData.createData(ConvertData.java:353) at
com.trivisionsc.ConvertData.excuteConvert(ConvertData.java:314) at
com.trivisionsc.ConvertData$1.actionPerformed(ConvertData.java:116) at
javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at
javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at
javax.swing.DefaultButtonModel.setPressed(Unknown Source) at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at
java.awt.Component.processMouseEvent(Unknown Source) at
javax.swing.JComponent.processMouseEvent(Unknown Source) at
java.awt.Component.processEvent(Unknown Source) at
java.awt.Container.processEvent(Unknown Source) at
java.awt.Component.dispatchEventImpl(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at
java.awt.Container.dispatchEventImpl(Unknown Source) at
java.awt.Window.dispatchEventImpl(Unknown Source) at
java.awt.Component.dispatchEvent(Unknown Source) at
java.awt.EventQueue.dispatchEvent(Unknown Source) at …Run Code Online (Sandbox Code Playgroud) 我想用这样的拼音转换斜线替换一个拼音符号:
/anycharacter*ou*anycharacter/
Run Code Online (Sandbox Code Playgroud)
至
/anycharacter*au*anycharacter/
Run Code Online (Sandbox Code Playgroud)
我的意思是我想在所有情况下在任何两个语音斜线之间用"au"替换"ou".例如:
<font size=+2 color=#E66C2C> jocose /d??'kous/</font>
= suj vour ver / suwj dduaf
Run Code Online (Sandbox Code Playgroud)
成
<font size=+2 color=#E66C2C> jocose /d??'kaus/</font>
= suj vour ver / suwj dduaf
Run Code Online (Sandbox Code Playgroud)
到目前为止,我一直在使用:
Find: \/(.*?)\bou*\b(.*?)\/\s
Replace: /\1au\2\3\4/
Run Code Online (Sandbox Code Playgroud)
但是它会找到任何/.../之间的所有字符串,包括正常的正斜杠和HTLM斜线,当替换它时会绕过诸如/ gou /,/ tou /等项目.与上面的例子一样,输出是:
<font size=+2 color=#E66C2C> jocose /d??'kaus/</font>
= suj vaur ver / suwj dduaf
Run Code Online (Sandbox Code Playgroud)
注意:正常斜线之前的"vour"被"vaur"取代不是我的目的.
你能指导我如何解决上述问题吗?非常感谢.