Note that there are some explanatory texts on larger screens.

plurals
  1. POFavourite content is not shown correctly on webview
    primarykey
    data
    text
    <p>I'm developing a language dictionary app. I save the favourite word into Preference. The Favourite content in the XML file looks like the following:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version='1.0' encoding='utf-8' standalone='yes' ?&gt; &lt;map&gt; &lt;string name="history"&gt; dict_name::160170::hi,dict_name::157140::he-man,dict_name::184774::jet,dict_name::34527::black &lt;/string&gt; &lt;string name="waitingTime"&gt; 0 &lt;/string&gt; &lt;boolean name="saveFavourite" value="true" /&gt; &lt;string name="defaultDictionary"&gt; dict_name &lt;/string&gt; &lt;string name="favourite"&gt; dict_name::149271::go,dict_name::25481::back,dict_name::184774::jet &lt;/string&gt; &lt;boolean name="saveHistory" value="true" /&gt; &lt;/map&gt; </code></pre> <p>I use the following code to load the Favourite content into the webview:</p> <pre class="lang-java prettyprint-override"><code>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&lt;String&gt; lstDict = null; private ArrayList&lt;Integer&gt; lstId = null; private ArrayList&lt;String&gt; mWordFavourite = null; private ArrayAdapter&lt;String&gt; aptList = null; private SharedPreferences prefs; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.favourite); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); if (prefs.getBoolean("saveFavourite", true)) { String strFavourite = prefs.getString("favourite", ""); Log.i(FAVOURITE_TAG, "Favourite loaded"); if (strFavourite != null &amp;&amp; !strFavourite.equals("")) { mWordFavourite = new ArrayList&lt;String&gt;(Arrays.asList(strFavourite.split(","))); } else { mWordFavourite = new ArrayList&lt;String&gt;(); } } else { mWordFavourite = new ArrayList&lt;String&gt;(); } Log.d(FAVOURITE_TAG, "mWordFavourite = " + mWordFavourite.size()); mLSTFavourite = (ListView) findViewById(R.id.lstFavourite); ImageButton btnClear = (ImageButton) findViewById(R.id.btnClear); ImageButton btnBackToContent = (ImageButton) findViewById(R.id.btnBackToContent); if (lstDict == null) { lstDict = new ArrayList&lt;String&gt;(); lstId = new ArrayList&lt;Integer&gt;(); aptList = new ArrayAdapter&lt;String&gt;(getApplicationContext(), R.layout.customlist); } lstDict.clear(); lstId.clear(); aptList.clear(); if (mWordFavourite != null &amp;&amp; mWordFavourite.size() &gt; 0) { try { for (int i = 0; i &lt; mWordFavourite.size(); i++) { Log.i(FAVOURITE_TAG, "item = " + mWordFavourite.get(i)); String arrPart[] = mWordFavourite.get(i).split("::"); if (arrPart.length == 3) { Log.i(CONTENT_TAG, "loaded content " + arrPart.length + ", wordId = " + arrPart[1]); // Log.i(CONTENT_TAG, "loaded 0"); lstDict.add(i, arrPart[0]); // Log.i(CONTENT_TAG, "loaded 1"); lstId.add(i, Integer.parseInt(arrPart[1])); // Log.i(CONTENT_TAG, "loaded 2"); aptList.add(arrPart[2]); } else { Log.i(FAVOURITE_TAG, "Wrong entry: " + mWordFavourite.get(i)); } } } catch (Exception ex) { Log.i(FAVOURITE_TAG, "Wrong entry found!"); } } // Log.i(CONTENT_TAG,"Adapter size = " + aptList.getCount()); // assign result return mLSTFavourite.setAdapter(aptList); mLSTFavourite.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; arg0, View v, int arg2, long arg3) { // mEDWord.setText(mAdapter.getItem(arg2)); Intent i = new Intent(); i.putExtra("dict", lstDict.get(arg2)); i.putExtra("wordId", lstId.get(arg2)); setResult(RESULT_OK, i); finish(); } }); btnClear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mWordFavourite.clear(); aptList.clear(); mLSTFavourite.setAdapter(aptList); SharedPreferences.Editor editor = prefs.edit(); editor.putString("favourite", ""); editor.commit(); setResult(RESULT_OK); finish(); } }); btnBackToContent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setResult(RESULT_CANCELED); finish(); } }); } } </code></pre> <p>The Favourite content is successfully loaded. The favourite words are listed in the webview. But the problem is that it only shows the definition of the latest word added to the Favourite regardless of what word is chosen. For example:</p> <pre><code>word1 word2 word3 </code></pre> <p>Despite word1 and/or word2 is selected for meaning, the definition of the last word, which is word3, is always shown. My purpose is to display the definition of <code>word1</code> when <code>word1</code> is selected, and the definition of <code>word2</code> when <code>word2</code> is selected, and so on and so forth. I save my dictionary data in SQLite database.</p> <p>Can anybody there help to solve this problem.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload