Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 2 của 2
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Chuyển 1 list Item giữa 2 activity?

    Mình có 1 vấn đề như sau: Mình lấy tất cả các image từ SDCard đưa vào 1 list (trong Activity1). Sau đó mình muốn chuyển cái list này qua Activity2 để xử lý :
    Ở Activity1 :
    Mã:
    public List<Item> list;
    private GridView gv;
    ....
    int i = 0; 
    while (i < cursor.getCount()){  
       cursor.moveToNext();  
       String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));  
       Bitmap img = BitmapFactory.decodeFile(path);  
       String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));  
       list.add(new Item(name,img));
       i++;
    }
    ...
    gv.setOnItemClickListener(new OnItemClickListener() {
       public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    
          Toast.makeText(gripview_anh.this, "Anh " + position, Toast.LENGTH_SHORT).show();
                        
          //Tạo 1 đối tượng Bundle để gửi đi cùng Intent
          Bundle sendBundle = new Bundle();
          sendBundle.putInt("khoa", position);                    
                        
          //Tạo Intent để khởi chạy Activity2 và gắn sendBundble vào Intent
          Intent i = new Intent(gripview_anh.this, view_image.class);
          i.putExtras(sendBundle);
          startActivity(i);                    
       }
    });
    Ở Activity2:
    Mã:
    //Lấy về Bundle được gửi kèm Intent rồi lấy ra giá trị
            Bundle receiveBundle = this.getIntent().getExtras();
            int position = receiveBundle.getInt("khoa");
    
            ImageView image = (ImageView)findViewById(R.id.imageview);
            image.setImageResource(Giá_Trị_Cần_Hiển_Thị);
    Nhưng phần màu đỏ ở Activity2 ("Giá_Trị_Cần_Hiển_Thị"). Làm sao để lấy giá trị trong list để hiển thị ra.

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •