Android中

时间:2015-09-22 04:27:26

标签: android android-camera-intent

目前,我添加了Horizo​​ntalScrollView在List View的每个项目中,每个Horizo​​ntalScrollView根据从sqlite获取的数据动态显示图像。 Sqlite预装了从我们的应用程序服务器下载的数据。

此外,在每个列表项目中,相机'按钮已添加。在此按钮的单击事件上,我将从Camera捕获的图像添加到现有的Horizo​​ntalScrollView。

1)首先,我试图在ArrayAdapter中的sqlite中在Horizo​​ntalScrollView中动态显示图像 -

 @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        final Holder holder;
        if (row == null) {
            LayoutInflater vi;
            vi = LayoutInflater.from(getContext());
            row = vi.inflate(R.layout.all_post_row, null);
            holder = new Holder(); 
            holder.imgBtn_Camera = (ImageView) row.findViewById(R.id.imgButton_Camera);
            holder.imgBtn_Audio = (ImageView) row.findViewById(R.id.imgButton_RecordAudio);
            holder.horizontalScrollView = (HorizontalScrollView) row.findViewById(R.id.hlist);
            holder.lLinearLayout = (LinearLayout) row.findViewById(R.id.innerlay);
            row.setTag(holder);
        } else {
            holder = (Holder) row.getTag();}

    strListItem_ActivityId = all_Post.getStrActivityId();
    dbhelper = new MyDbHelper(AllPosts_Page.this);
    SQLiteDatabase db = dbhelper.getReadableDatabase();
    Cursor cursor = db.rawQuery("select * from ActivityObjectList where activityId " + "= ? ", new String[]{strListItem_ActivityId});
    imageArray.clear();
    if (cursor.moveToFirst()) {
        do {
            String imagePath = cursor.getString(cursor.getColumnIndex("imageaudioPath"));
            Log.e("imagePath ", " = " + imagePath);
            imageArray.add(imagePath);
        }
        while (cursor.moveToNext());
    }
    cursor.close();
    db.close();

    holder.lLinearLayout.removeAllViews();

    final Iterator<String> it = imageArray.iterator();
    while (it.hasNext()) {
        LayoutInflater mInflater;
        mInflater = LayoutInflater.from(getContext());
        View cur_deal = mInflater.inflate(R.layout.horizontalitem,      holder.lLinearLayout, false);

        imageView = (ImageView) cur_deal.findViewById(R.id.image_AllPost);
        pBar = (ProgressBar) cur_deal.findViewById(R.id.pBar_AllPost);
        pBar.setVisibility(View.VISIBLE);
        holder.lLinearLayout.addView(cur_deal);

        final String imgElement = it.next();
        String baseDir =  Environment.getExternalStorageDirectory().getAbsolutePath();
       String path = baseDir + "/classnkk_images/" + imgElement;
       Log.e("path ", " = " + path);

    File photos = new File(path);
    final Bitmap bitmapResizeImage = decodeFile(photos);
    imageView.setImageBitmap(bitmapResizeImage);
    }

2)这是我在ArrayAdapter类中的Camera按钮单击事件 -

holder.imgBtn_Camera.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
        Toast.makeText(context, "Camera" + " = ", Toast.LENGTH_SHORT).show();
        Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ((Activity) context).startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
    }
});

3)这是onActivityResult方法实现,它位于Activity类 -

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

   if (requestCode == CAMERA_PIC_REQUEST && resultCode == Activity.RESULT_OK)
    {
       {
            onActivityResult(requestCode, resultCode, data);
            Bitmap bp = (Bitmap) data.getExtras().get("data");
            imageView.setImageBitmap(bp);
        }
     }
  }

上面的代码应该显示从相机捕获到Horizo​​ntalScrollView的图像。 。我无法理解它出了什么问题?我试图以多种方式修改代码。但它没有帮助。

我试图解决这个问题15天。请有人帮我解决这个问题。

先谢谢。

0 个答案:

没有答案