0

Currently , i added HorizontalScrollView In each item of List View each HorizontalScrollView displayes the images dynamically on the basis of data fetched from the sqlite. Sqlite is preloaded with the data that is downloaded from our application server.

Also, In each list item 'Camera' button is added. On click event of this button I am adding images captured from Camera to the existing HorizontalScrollView.

1) First I'm trying to show images dynamically in HorizontalScrollView from sqlite in ArrayAdapter -

 @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) Here is my Camera button click event in ArrayAdapter class -

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) Here is onActivityResult method implementation which is in Activity class -

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);
        }
     }
  }

The above code should show the images captured from camera into HorizontalScrollView. . I am not able to understand where does it went wrong ? I have tried to modify code in many ways. However it did not help.

I'm trying to solve this issue since 15 days.Please someone help me for this question.

Thanks in advanced.

androidTag
  • 5,053
  • 7
  • 19
  • 28
  • 'imageView.setImageBitmap(bp);'. Where did you define imageView? The one you use in getView should be local to getView only. What do you think to which item imageView would refer to when you scroll the list? – greenapps Sep 22 '15 at 05:30
  • 1
    I define the ImageView before onCreate() method and initialize in iterator in getView = 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); } – androidTag Sep 22 '15 at 05:38
  • Please do not post code in comments. Do not post the same code again. 'I define the ImageView before onCreate()'. Well that is wrong. Define it in getView as i already said before. Then rethink how you can put the bitmap in the right view of the right item. You should do that in getView. – greenapps Sep 22 '15 at 05:48
  • But how can set the captured image in getview from camera ? How to work with onActivityResult for listview item in Adapter ? – androidTag Sep 22 '15 at 05:51
  • Can someone answer ? – androidTag Sep 22 '15 at 07:33
  • I tried this link ( http://stackoverflow.com/questions/2729267/android-camera-intent ) but very huge size image is showing in always in second item image view and second time when run the app image is not there is horizontal scrollview. – androidTag Sep 22 '15 at 10:31
  • The image is somewhere on the device. And getView does know for which item it has to be used. Then you only have to call notifyDataSetChanged on the adapter and getView will be called. This is the normal procedure when images or texts change fir items. – greenapps Sep 22 '15 at 18:19
  • @greenapps: yes my captured images are in sd card folder but , how to work with for each item.Can you please give me some code idea. – androidTag Sep 23 '15 at 03:43
  • In getView you have 'String path = baseDir + "/classnkk_images/" + imgElement;'. Just take the path to your new image there for the right item. – greenapps Sep 23 '15 at 05:55
  • How to get right item from getview in onActivityForResult. Thats why I'm posting this question. I cant understand how to get resolve? – androidTag Sep 23 '15 at 06:02
  • You should get the 'position' of the item in onClick(View v) already.. And then save that in a private variable of your class. Then later use that variable/position in onActivityResult. – greenapps Sep 23 '15 at 10:59
  • Please can someone help me for this issue ? – androidTag Sep 24 '15 at 04:01
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/90493/discussion-between-androidtag-and-greenapps). – androidTag Sep 24 '15 at 04:31

0 Answers0