0
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    JSONObject json = jParser.getJSONFromUrl("http://domain.com/directory/database/retrieveComments.php?placeId=" + stringPlaceId);
    try
    {
        commentsRatingsArray = json.getJSONArray("commentsRatings");
        for(int i = 0; i < commentsRatingsArray.length(); i++)
        {
        JSONObject jsonObject = commentsRatingsArray.getJSONObject(i);
        String dbUserFullName = jsonObject.getString(TAG_FULLNAME);
        String dbUserEmail = jsonObject.getString(TAG_EMAIL);
        String dbComment = jsonObject.getString(TAG_COMMENT);
        String dbRating = jsonObject.getString(TAG_RATING);
        String dbDate = jsonObject.getString(TAG_DATE);
        String dbTime = jsonObject.getString(TAG_TIME);

        HashMap<String, String> map = new HashMap<String, String>();
        map.put(TAG_FULLNAME, dbUserFullName);
        map.put(TAG_EMAIL, dbUserEmail);
        map.put(TAG_COMMENT, dbComment);
        map.put(TAG_RATING, dbRating);
        map.put(TAG_DATE, dbDate);
        map.put(TAG_TIME, dbTime);

        list.add(map);
    }   
}
catch (Exception e)
{
     e.printStackTrace();
     Toast.makeText(getBaseContext(), "Connection to the server is lost. Please check your internet connection.", Toast.LENGTH_SHORT).show();
}

ListAdapter adapter = new SimpleAdapter
(DisplayCommentsRatings.this, list, R.layout.commentrating,

     new String[] { TAG_FULLNAME, TAG_EMAIL, TAG_COMMENT, TAG_DATE,  TAG_TIME },
     new int[] {R.id.tvUserFullName, R.id.tvUserEmail, R.id.tvUserComment, R.id.tvDate, R.id.tvTime });

     setListAdapter(adapter);

これが私のコードです。データベースからこれらの JSON 配列の値を取得しています。リスト ビュー内で画像の src を変更する方法を知りたいだけです。使用する画像は 5 つだけなので、これらの画像を Web にアップロードする代わりに、アセット フォルダーに含めることにしました。

誰かがこれを可能にするアイデアを教えてもらえますか?

ここに私のXMLコードがあります:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/tvUserFullName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:textSize="12dip"
        android:textStyle="bold"/>
            //This is the imageView where I will display the image from the assets folder
    <ImageView
        android:id="@+id/ivUserRating"
        android:layout_width="100dip"
        android:layout_height="fill_parent"
        android:src="@drawable/zerostar"/>

</LinearLayout>

<TextView
    android:id="@+id/tvUserEmail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="EmailAddress@domain.com"
    android:textSize="9dip"/>

<TextView
    android:id="@+id/tvUserComment"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text='"This is a comment. This is a comment. This is a comment. This is a comment. This is a comment."'
    android:textSize="10dip"
    android:layout_margin="3dip"
    android:textColor="#000000"
    android:maxLength="300"/>

<TextView
    android:id="@+id/tvDate"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="August 1, 2010"
    android:textColor="#000000"
    android:textSize="8dip"
    android:layout_gravity="right"/>

<TextView
    android:id="@+id/tvTime"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:text="08:20 PM"
    android:textColor="#000000"
    android:textSize="8dip"
    android:layout_gravity="right"/>

4

2 に答える 2

0

位置を確認して、

Bitmap bmp=null;

if(position==0){

   bitmap=getBitmap("img0.png");

}else if  (position==1){

   bitmap=getBitmap("img1.png");
}
.
.
.

方法::

private Bitmap getBitmap(String name) throws IOException
        {
            AssetManager asset = getAssets();

            InputStream is = asset.open(name);
            Bitmap bitmap = BitmapFactory.decodeStream(is);

            return bitmap;
        }
于 2012-08-08T09:19:30.547 に答える