즐겨찾기 컨텐츠가 웹뷰에 올바르게 표시되지 않음
저는 어학사전 앱을 개발하고 있습니다.좋아하는 단어를 Preferences에 저장합니다.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>
다음 코드를 사용하여 즐겨찾기 콘텐츠를 웹뷰에 로드합니다.
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 = 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 && !strFavourite.equals("")) {
mWordFavourite = new ArrayList<String>(Arrays.asList(strFavourite.split(",")));
} else {
mWordFavourite = new ArrayList<String>();
}
} else {
mWordFavourite = new ArrayList<String>();
}
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<String>();
lstId = new ArrayList<Integer>();
aptList = new ArrayAdapter<String>(getApplicationContext(), R.layout.customlist);
}
lstDict.clear();
lstId.clear();
aptList.clear();
if (mWordFavourite != null && mWordFavourite.size() > 0) {
try {
for (int i = 0; i < 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<?> 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();
}
});
}
}
즐겨찾기 콘텐츠가 성공적으로 로드되었습니다.즐겨찾기 단어가 웹뷰에 나열됩니다.그러나 문제는 어떤 단어를 선택하든 상관없이 즐겨찾기에 추가된 최신 단어의 정의만 보여준다는 것입니다.예를 들어,
word1
word2
word3
word1 및/또는 word2가 의미로 선택되더라도 마지막 단어인 word3의 정의는 항상 표시됩니다.내 목적은 다음의 정의를 표시하는 것입니다.word1언제word1를 선택하고, 의 정의를 실행합니다.word2언제word2가 선택되어 있습니다.SQLite 데이터베이스에 사전 데이터를 저장합니다.
거기에 있는 누구라도 이 문제를 해결하는 데 도움을 줄 수 있습니까?
문제는 이 선에서 비롯된다고 생각합니다.
mWordFavourite = new ArrayList<String>(Arrays.asList(strFavourite.split(",")));
여기서 새 배열 목록을 생성합니다.<string>매번 물건을 만들지만 당신은 그것에 추가해야 합니까?& 마지막 하나를 구하라 그렇지 않으면 한 변수에 넣어야 합니다.
사이즈()>0인지 확인하시는 경우
그러나 추가되지 않은 새 개체를 생성할 때마다
내가 틀렸을지도 몰라요!
http://developer.android.com/reference/android/webkit/WebView.html
자세한 정보는 위의 링크를 참조하시기 바랍니다.
언급URL : https://stackoverflow.com/questions/9477970/favourite-content-is-not-shown-correctly-on-webview
'programing' 카테고리의 다른 글
| Visual Studio IDE에서 XSD를 이용한 XML 검증 (0) | 2023.09.14 |
|---|---|
| 오류 2003(HY000):localhost(10061)에서 MySQL 서버에 연결할 수 없습니다. (0) | 2023.09.14 |
| 아두이노 HTTPS 지원 예정 (0) | 2023.09.14 |
| 윈도우의 URL 해시를 다른 응답으로 대체하려면 어떻게 해야 합니까? (0) | 2023.09.14 |
| Android용 XML 특성의 물음표(?) (0) | 2023.09.14 |