搜索栏与文本相关联

搜索栏与文本相关联

我正在尝试将我的搜索栏与文本相关联。在帮助下,我尝试这样做,但是我的尝试没有成功。

我也想在下面的代码中包含一个范围查找栏,但是不确定如何解决。任何帮助将不胜感激。

public class ProfileCreation extends Activity {

    private static final int RESULT_LOAD_IMAGE = 1;
    FrameLayout layout;
    Button save;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_creation);
        save = (Button) findViewById(R.id.button2);
        String picturePath = PreferenceManager.getDefaultSharedPreferences(this).getString("picturePath", "");
        if (!picturePath.equals("")) {
            ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
            imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
        }


        Button buttonLoadImage = (Button) findViewById(R.id.btnPictureSelect);
        buttonLoadImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent i = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(i, RESULT_LOAD_IMAGE);
            }
        });
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // Locate the image in res >
                Bitmap bitmap = BitmapFactory.decodeFile("picturePath");
                // Convert it to byte
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                // Compress image to lower quality scale 1 - 100
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

                Object image = null;
                try {
                    String path = null;
                    image = readInFile(path);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                // Create the ParseFile
                ParseFile file = new ParseFile("picturePath", (byte[]) image);
                // Upload the image into Parse Cloud
                file.saveInBackground();

                // Create a New Class called "ImageUpload" in Parse
                ParseObject imgupload = new ParseObject("Image");

                // Create a column named "ImageName" and set the string
                imgupload.put("Image", "picturePath");


                // Create a column named "ImageFile" and insert the image
                imgupload.put("ImageFile", file);

                // Create the class and the columns
                imgupload.saveInBackground();

                // Show a simple toast message

                SeekBar seekBar = (SeekBar) findViewById(R.id.seekBarDistance);
                final TextView seekBarValue = (TextView) findViewById(R.id.seekBarDistanceValue);

                seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

                    @Override
                    public void onProgressChanged(SeekBar seekBar, int progress,
                                                  boolean fromUser) {
                        // TODO Auto-generated method stub
                        seekBarValue.setText(String.valueOf(progress));
                    }

                    @Override
                    public void onStartTrackingTouch(SeekBar seekBar) {
                        // TODO Auto-generated method stub
                    }

                    @Override
                    public void onStopTrackingTouch(SeekBar seekBar) {
                        // TODO Auto-generated method stub
                    }
                });
            }
        });
    }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            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();

                ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
                imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

            }

        }

        private byte[] readInFile(String path) throws IOException {
            // TODO Auto-generated method stub
            byte[] data = null;
            File file = new File(path);
            InputStream input_stream = new BufferedInputStream(new FileInputStream(
                    file));
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            data = new byte[16384]; // 16K
            int bytes_read;
            while ((bytes_read = input_stream.read(data, 0, data.length)) != -1) {
                buffer.write(data, 0, bytes_read);
            }
            input_stream.close();
            return buffer.toByteArray();

        }
    }


更新的代码

public class ProfileCreation extends Activity {

    private static final int RESULT_LOAD_IMAGE = 1;
    FrameLayout layout;
    Button save;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_creation);
        save = (Button) findViewById(R.id.button2);
        String picturePath = PreferenceManager.getDefaultSharedPreferences(this).getString("picturePath", "");
        if (!picturePath.equals("")) {
            ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
            imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
        }

        SeekBar seekBar = (SeekBar) findViewById(R.id.seekBarDistance);
        final TextView seekBarValue = (TextView) findViewById(R.id.seekBarDistanceValue);

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                seekBarValue.setText(String.valueOf(progress));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
            }

        }


        Button buttonLoadImage = (Button) findViewById(R.id.btnPictureSelect);
        buttonLoadImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent i = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(i, RESULT_LOAD_IMAGE);
            }
        });
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // Locate the image in res >
                Bitmap bitmap = BitmapFactory.decodeFile("picturePath");
                // Convert it to byte
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                // Compress image to lower quality scale 1 - 100
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

                Object image = null;
                try {
                    String path = null;
                    image = readInFile(path);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                // Create the ParseFile
                ParseFile file = new ParseFile("picturePath", (byte[]) image);
                // Upload the image into Parse Cloud
                file.saveInBackground();

                // Create a New Class called "ImageUpload" in Parse
                ParseObject imgupload = new ParseObject("Image");

                // Create a column named "ImageName" and set the string
                imgupload.put("Image", "picturePath");


                // Create a column named "ImageFile" and insert the image
                imgupload.put("ImageFile", file);

                // Create the class and the columns
                imgupload.saveInBackground();

                // Show a simple toast message


            }
        });
    }

        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            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();

                ImageView imageView = (ImageView) findViewById(R.id.profilePicturePreview);
                imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

            }

        }

        private byte[] readInFile(String path) throws IOException {
            // TODO Auto-generated method stub
            byte[] data = null;
            File file = new File(path);
            InputStream input_stream = new BufferedInputStream(new FileInputStream(
                    file));
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            data = new byte[16384]; // 16K
            int bytes_read;
            while ((bytes_read = input_stream.read(data, 0, data.length)) != -1) {
                buffer.write(data, 0, bytes_read);
            }
            input_stream.close();
            return buffer.toByteArray();

        }
    }

最佳答案

下面的代码段应移出onClickListener。写在onCreate

 SeekBar seekBar = (SeekBar) findViewById(R.id.seekBarDistance);
    final TextView seekBarValue = (TextView) findViewById(R.id.seekBarDistanceValue);

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {
            // TODO Auto-generated method stub
            seekBarValue.setText(String.valueOf(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // TODO Auto-generated method stub
        }
    });

08-04 08:38