0

我成功地将数据从列表视图传递到下一个活动,但现在我需要将数据库中的图像添加到列表视图,然后将其传递给下一个活动。或者,如果它是最简单的,只需将图像传递给下一个活动而不在列表视图中显示它。

package com.example.assfar.travel_guide;

import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.example.assfar.R;
import com.example.assfar.database.DBHelper;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;



public class TravelGuide extends ListActivity {

    private DBHelper dataBase;
    private List<String> guide_title_list= new ArrayList<String>();
    HashMap<String,String> details= new HashMap<String,String>();
    private Cursor cursor;
    String title;
    Integer id;
    String desc;
    private ImageView imgv;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.travelguide);

        imgv = (ImageView) findViewById(R.id.image);

        dataBase=  DBHelper.instance();
        SQLiteDatabase db= dataBase.getWritableDatabase();

        cursor= db.rawQuery("select * from Tour_Guide", null);

        if(cursor!=null) {
             if(cursor.moveToFirst());
             {
                do
                  {

         desc = cursor.getString(cursor.getColumnIndex("tour_Description"));
         title= cursor.getString(cursor.getColumnIndex("guide_title")); 
         id= cursor.getInt(cursor.getColumnIndex("_id"));
               guide_title_list.add("" + title +id );
                 details.put("" + title +id  ,title+desc+imgv);

                  } while(cursor.moveToNext());

             }

         }

        this.setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, guide_title_list));

    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
       super.onListItemClick(l, v, position, id);

       //String selectedItem= ((TextView) v).getText().toString();

       String selectedValue= (String) getListAdapter(). getItem(position);
       String itemTitleDesc=(String) details.get(selectedValue);

       Intent i = new Intent(TravelGuide.this, Travel_Guide_Details.class);

        i.putExtra("selected item", selectedValue);
        i.putExtra("selected item", itemTitleDesc);
        startActivity(i);

        }
}
4

0 回答 0