图像发送问题,能够将文本发送到另一个活动,放置一些带有文件名的源代码请查看并告诉我错误和可能,所以请写下所需的代码,因为我在过去两天都面临这个问题:-
MainActivity 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();
byte[] array = null;
Bitmap thumb_url = BitmapFactory.decodeByteArray
(array, 0, array.length);
// Bitmap bMap = BitmapFactory.decodeByteArray
(array, 0, array.length);
// 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, thumb_url);
startActivity(in);
}
});
}
}
SingleMenuItemActivity
public class SingleMenuItemActivity extends Activity {
// XML node keys
private static final String KEY_TITLE = "title";
private static final String KEY_ARTIST = "artist";
private static final String KEY_DURATION = "duration";
private static final String KEY_THUMB_URL = "thumb_url";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_item);
// 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)this.getIntent().getParcelableExtra("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);
//what code to write for image here
lblName.setText(title);
lblCost.setText(artist);
lblDesc.setText(duration);
listitem.xml:-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/thumb_url"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/rihanna"/>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#43bd00"
android:textSize="16sp"
android:textStyle="bold"
android:paddingTop="6dip"
android:paddingBottom="2dip" />
<TextView
android:id="@+id/artist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#acacac"
android:paddingBottom="2dip">
</TextView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#5d5d5d"
android:gravity="left"
android:textStyle="bold"
android:text="Duration: " >
</TextView>
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#acacac"
android:textStyle="bold"
android:gravity="left">
</TextView>
</LinearLayout>