1

URLからリストビューにデータをフェッチしています。ユーザーがリストビューアイテムをクリックすると、選択したアイテムの詳細が画像とともにユーザーに表示され、テキストデータを別のアクティビティに送信しますが、画像を送信できませんが、単一のアイテムで表示されます。アクティビティimageviewで画像の代わりに空白が表示されますが、この問題を解決するにはどうすればよいですか?参照用のコード:-

     ListViewActivity Code:-   

    public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
 // getting values from selected ListItem
String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
String artist = ((TextView) view.findViewById(R.id.artist)).getText().toString();
String duration = ((TextView) view.findViewById(R.id.duration)).getText().
    toString();
String image = ((ImageView)view.findViewById(R.id.list_image))
    .getImageMatrix().toString();

// Starting new intent
Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);
in.putExtra(KEY_TITLE, title);
in.putExtra(KEY_ARTIST, artist);
in.putExtra(KEY_DURATION, duration);
in.putExtra(KEY_THUMB_URL, image);
startActivity(in);

     SingleItemActivity Code:-
    // getting intent data
    Intent in = getIntent();

    // Get XML values from previous intent

    String title = in.getStringExtra(KEY_TITLE);
    String artist = in.getStringExtra(KEY_ARTIST);
    String duration = in.getStringExtra(KEY_DURATION);
    Bitmap bitmap =(Bitmap) in.getParcelableExtra(KEY_THUMB_URL);




    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.name_label);
    TextView lblCost = (TextView) findViewById(R.id.email_label);
    TextView lblDesc = (TextView) findViewById(R.id.mobile_label);     
    ImageView image = (ImageView)findViewById(R.id.image_label);
    image.setImageBitmap(bitmap);   


    lblName.setText(title);
    lblCost.setText(artist);
    lblDesc.setText(duration);

     SingleItemXML Code:-
     <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent">

    <ImageView     
        android:id="@+id/image_label"   
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/rihanna"
        />


        <TextView android:id="@+id/name_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="25dip"
        android:textStyle="bold"
        android:paddingTop="10dip"
        android:paddingBottom="10dip"
        android:textColor="#43bd00"/>

        <TextView android:id="@+id/email_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#acacac"/>

       <TextView android:id="@+id/mobile_label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textStyle="bold"/>

        </LinearLayout>
4

2 に答える 2

0

ImageView からビットマップを取得するには、buildDrawingCache()andを使用する必要があります。getDrawingCache()onItemClick()

imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();

Intent intent = new Intent(context, next_activity.this);
intent.putExtra("image", bitmap);
startActivity(intent);

次のアクティビティで取得するため、

bitmap = getIntent().getParcelableExtra("image");
于 2012-10-06T06:35:01.113 に答える
0

in.putExtra(KEY_THUMB_URL, 画像);

画像を BASE64 文字列形式に変換します。新しいアクティビティで、BASE64 文字列を再度画像に変換します。

public String bitMapToString(Bitmap bitmap) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
        byte[] b = baos.toByteArray();
        String stringBody = null;
        try {
            stringBody = Base64.encodeToString(b, Base64.DEFAULT).toString();
        } catch (Exception e) {
            toast(e.toString());
            e.printStackTrace();
        }
        return stringBody;
    }
于 2012-10-06T06:36:28.110 に答える