Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将图像从一个活动发送到另一个活动,使用xml解析器在listview中获取记录_Android_Android Layout_Android Intent_Android Emulator - Fatal编程技术网

Android 如何将图像从一个活动发送到另一个活动,使用xml解析器在listview中获取记录

Android 如何将图像从一个活动发送到另一个活动,使用xml解析器在listview中获取记录,android,android-layout,android-intent,android-emulator,Android,Android Layout,Android Intent,Android Emulator,图像发送中出现问题,无法向其他活动发送文本,放置了一些带有文件名的源代码。请查看并告诉我错误和可能的原因,因此请写下所需的代码,因为我在过去两天中一直面临此问题:- MainActivity Code:- public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // getting values from selected L

图像发送中出现问题,无法向其他活动发送文本,放置了一些带有文件名的源代码。请查看并告诉我错误和可能的原因,因此请写下所需的代码,因为我在过去两天中一直面临此问题:-

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>
main活动代码:-
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//从选定的ListItem获取值
字符串标题=((TextView)view.findViewById
(R.id.title)).getText().toString();
字符串艺术家=((TextView)view.findViewById
(R.id.artist)).getText().toString();
字符串持续时间=((TextView)view.findViewById
(R.id.duration)).getText().toString();
字节[]数组=null;
位图thumb\u url=BitmapFactory.decodeByteArray
(数组,0,array.length);
//位图bMap=BitmapFactory.decodeByteArray
(数组,0,array.length);
//开始新的意图
Intent in=新的Intent(getApplicationContext(),
SingleMenuItemActivity.class);
in.putExtra(图例标题、标题);
in.putExtra(基尤艺术家、艺术家);
in.putExtra(按键持续时间,持续时间);
in.putExtra(KEY\u THUMB\u URL,THUMB\u URL);
星触觉(in);
}
});     
}   
}
单菜单活动
公共类SingleMenuItemActivity扩展活动{
//XML节点密钥
私有静态最终字符串键\u TITLE=“TITLE”;
私有静态最终字符串键\u ARTIST=“ARTIST”;
私有静态最终字符串键\u DURATION=“DURATION”;
私有静态最终字符串键\u THUMB\u URL=“THUMB\u URL”;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_项);
//获取意图数据
Intent in=getIntent();
//从以前的意图中获取XML值
字符串标题=in.getStringExtra(键标题);
字符串艺术家=in.getStringExtra(键艺术家);
字符串持续时间=in.getStringExtra(键持续时间);
位图位图=(位图)this.getIntent().getParcelableExtra(“拇指url”);
//在屏幕上显示所有值
TextView lblName=(TextView)findViewById(R.id.name\u标签);
TextView lblCost=(TextView)findViewById(R.id.email_标签);
TextView lblDesc=(TextView)findViewById(R.id.mobile_标签);
//在这里为图像编写什么代码
lblName.setText(标题);
lblCost.setText(艺术家);
lblDesc.setText(持续时间);
listitem.xml:-
这是单击方法

in.putExtra(KEY_THUMB_URL, thumb_url);  
并使用
setBackgroundResource
接收图像

 ImageView image = (ImageView)findViewById(R.id.imageView);
 bitmap.setBackgroundResource(thumb_url);