2012-03-19 9 views
1

私の最初の投稿は、現在データベースからデータを取り出してリストビューで表示する単純なアンドロイドアプリを作成中です。その90%は、そこから引き出すデータにHTMLエンティティが含まれていることを除いて行われます。ここにデータベースとカーソルのサンプルサンプルとそのレイアウトなどがあります:AndroidはデータベースのListview内のhtmlエンティティを置き換えます

これは単純なテストアプリケーションなので、私は学ぶことができます(そして最終的には適切なアプリケーションに変身します)。その背後にあるアイデアは、製品を選択すると、その製品に関する詳細を示す新しいインテントを開始することです(製品名またはIDを次のアクティビティに渡す)。

ここに私のlist_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

<LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_alignParentLeft="true"> 

    <TextView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/product_name" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="20sp" /> 

    <LinearLayout 
     android:id="@+id/linearLayout4" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/product_desc" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="15sp" /> 

    </LinearLayout> 

</LinearLayout> 
</RelativeLayout> 

はここ

だだが、ここではコード

final Cursor dataCursor = database.query("products", fields, null, null, null, null, "_id desc", null); 

    dataAdapter = new SimpleCursorAdapter(this, R.layout.list_item, dataCursor, fields, 
        new int[] { R.id.product_name, R.id.product_desc }); 

    this.setListAdapter(dataAdapter); 

    mListView.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, 
      int position, long id) { 

      Intent intent = new Intent(parent.getContext(), Filter.class); 
      intent.putExtra("product_name",dataCursor.getString(0)); 

      startActivity(intent); 

     } 
     }); 

はここで問題なのだ...、データベース内の一部のHTMLエンティティが含まれています。

データは次のように基本的である:

table products: 
________________________________________________ 
| product_name | product_desc | _id | 
------------------------------------------------ 
|Product1 Name&reg;| Super special |  1  | 
|Product1 Name&reg;| Super special |  2  | 
|Product1 Name&reg;| Super special |  3  | 
|Product1 Name&reg;| Super special |  4  | 
________________________________________________ 

私は達成するためにトリングだ何が®実体が実際に「登録」記号に変換され、リスト項目に示されてしまうことです。

私がここに見つけたものを適用しようとしましたが、それはうまくいきませんでした(人がカーソルを文字列の配列に使用していなかったため、わかりません)。 (そして明らかに私の経験はそれほど大きくない)。

私がテストするとき、リストアイテムを選択するときにシンプルなトーストを表示し、それをapache StringEscapeUtilsと共に使用すると、それはうまく動作し、®と他のhtmlエンティティは適切な(r)幻想的ですね。

Toast.makeText(getApplicationContext(), "Product Name is: " + StringEscapeUtils.unescapeHtml4(dataCursor.getString(0)), Toast.LENGTH_SHORT).show(); 

ご迷惑をおかけして申し訳ございません。

答えて

関連する問題