0

I have a listview which contains two buttons, when the button is clicked it should open a gallery. I tried to implement it and followed some post on stackoverflow but still I'm not able to get exact result. How to open the gallery using buttons in listViewlistview?

I have tried the following and used the adapter class as inner class

MyAdapter adapter=new MyAdapter(getApplicationContext(),videoFileList);

im my adapter class

 private class MyAdapter extends BaseAdapter
        {

         ImageView picture;
         Button imgbtn,videobtn;
         ImageButton play;
            Context context;
            private LayoutInflater inflater;
            private ArrayList<String> videolisty;
            public MyAdapter(Context context,ArrayList<String> videolistx)
            {
                this.context=context;
                inflater = LayoutInflater.from(context);
                videolisty = videolistx;
                Field[] arrayOfField = R.raw.class.getFields();
                for (int i = 0; ; i++)
                {
                  if (i >= arrayOfField.length)
                  {
                    System.out.println("-----------videolist------" +videoFileList);
                    return;
                  }
                  System.out.println("audio files-----" + arrayOfField[i].getName());
                  videoFilename.add(arrayOfField[i].getName());
                  Uri localUri = Uri.parse("android.resource://" + Listmodels.this.getPackageName() + "/" + "R.raw." + arrayOfField[i].getName());
                  System.out.println("--------uri path------" + localUri);
                }

            }

            @Override
            public int getCount() {
                return videolisty.size();
            }

            @Override
            public Object getItem(int i)
            {
                return videolisty.get(i);
            }

            @Override
            public long getItemId(int i)
            {
                return i;
            }

            @Override
            public View getView(int i, View view, ViewGroup viewGroup)
            {
                View v = view;

                final int xx = i;
                if(v == null)
                {
                   v = inflater.inflate(R.layout.clistview, viewGroup, false);
                   v.setTag(R.id.categoryimageView1, v.findViewById(R.id.categoryimageView1));
                   v.setTag(R.id.uploadimg, v.findViewById(R.id.uploadimg));
                   v.setTag(R.id.uploadvideo, v.findViewById(R.id.uploadvideo));
                   v.setTag(R.id.play, v.findViewById(R.id.play));
                }

                picture = (ImageView)v.getTag(R.id.categoryimageView1);
                imgbtn = (Button)v.getTag(R.id.uploadimg);
                videobtn = (Button)v.getTag(R.id.uploadvideo);
                play=(ImageButton)v.getTag(R.id.play);
                imgbtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                          Activity aa = (Activity)context;
                         aa.startActivityForResult(i, RESULT_LOAD_IMAGE);
                    }





                });

                play.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("YEST"+xx);
                        Intent localIntent = new Intent(Listmodels.this, Videoplay.class);
                        localIntent.putExtra("videopath", videoFileList.get(xx));
                        startActivity(localIntent);
                    }
                });

                /*picture.setImageResource(item.drawableId);
                name.setText(item.name);*/


                return v;
            }

            protected void onActivityResult(int requestCode, int resultCode) {
                super.onActivityResult(requestCode, resultCode, data);

                if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
                    Uri selectedImage = data.getData();
                    String[] filePathColumn = { MediaStore.Images.Media.DATA };

                    Cursor cursor = getContentResolver().query(selectedImage,
                            filePathColumn, null, null, null);
                    cursor.moveToFirst();

                    int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                   String picturePath = cursor.getString(columnIndex);
                    cursor.close();

                    System.out.println("------data path-------"+picturePath);

                    //filechoose.setText(picturePath);

                }






        }
user60578
  • 11
  • 4
  • `I'm not able to get exact result.` So what result are you getting exactly? – WarrenFaith May 21 '14 at 09:28
  • @WarrenFaith I'm not able to open the gallery. I have tried the following link http://stackoverflow.com/questions/17258722/onactivityresult-in-not-called-in-the-class-extended-from-arrayadapter – user60578 May 21 '14 at 09:30
  • Please dont make me ask for everything. What happens when you click on an entry in your list? Does it crash? Do you see a dialog to pick another app? Please be mor detailed about everything! – WarrenFaith May 21 '14 at 09:33
  • Did you try testing in different device? – Kailas May 21 '14 at 09:37
  • 1
    @WarrenFaith Ok, I will. It gives me a error and I didn't see any dialog. I have passed the context from activity class to adapter class which is inner class of activity. – user60578 May 21 '14 at 09:38
  • @Kailas: I'm using samsung device to testing. – user60578 May 21 '14 at 09:39
  • "Gives me an error". Cool, should I guess the error or do you tell us? Please add the error from logcat to your question, dont write it as a comment. – WarrenFaith May 21 '14 at 09:40
  • I gives error in super.onActivityResult(); – user60578 May 21 '14 at 09:48
  • Beside the fact that you still don't tell me the error itself (there is something like an error message!) but at least you said me which line causes the error. You can't implement onActivityResult() in your BaseAdapter. That method belongs to your Activity. – WarrenFaith May 21 '14 at 10:25
  • @WarrenFaith thanks for your response. super.onActivityResult(requestCode, resultCode, data); above line which is in protected void onActivityResult() method gives the error. – user60578 May 21 '14 at 12:34
  • I have understood it the first time you said it. You can't override that method in your BaseAdapter! That is basic java inheritance that you need to understand here. Move that method to your activity and you should see your error disappearing. And one thing for the third time: "gives an error" is under no circumstances a valid error description. You always need to state the error message that is displayed! In your case it should be "Cannot resolve method onActivityResult()" or similar. Please write that down, get a tattoo stating that whatever is necessary! **ALWAYS** state the error message – WarrenFaith May 21 '14 at 12:41

0 Answers0