Search code examples
androidsetseekbarandroid-seekbar

How to show the seekBar value in another class?


I have two list in Activity A. The value inside the listView were getting from Activity B. When the list is clicked, it suppose to go Activity B.

enter image description here

For the Progress value in A, it actually get from the seekBar.

Assume first list is clicked, the seekBar should shows 36 instead of 0 ! This is what I've tried so far.

enter image description here

Activity A

 listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { // if listView is clicked
            @Override
            public void onItemClick(AdapterView<?> a, View v, int position, long id) {
                Object o = listview.getItemAtPosition(position);
                SearchResults fullObject = (SearchResults) o;
                String temp = fullObject.getDescription();
                String[] ReceiveDescription = temp.split(":");
                String Progress=fullObject.getProgress();
                String[] ReceiveProgress=Progress.split(":");
                String TimeIn=fullObject.getTimeIn();
                String []ReceiveTimeIn=TimeIn.split(":");
                String TimeOut=fullObject.getTimeOut();
                String []ReceiveTimeOut=TimeOut.split(":");

                Intent i = new Intent(getApplication(), Add_Details_Information.class);
                i.putExtra("ReceiveProject", ReceiveProject);
                i.putExtra("ReceiveDescription", ReceiveDescription[1]);
                i.putExtra("ReceiveProgress", ReceiveProgress[1].getProgress()); //cannot resolve getProgress
                i.putExtra("ReceiveTimeIn", ReceiveTimeIn[1]);
                i.putExtra("ReceiveTimeOut", ReceiveTimeOut[1]);
                i.putExtra("date",date);
                i.putExtra("status", status);
                startActivityForResult(i,PROJECT_REQUEST_CODE);
            }
        });
    }

Activity B

 @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_details_information);
        addItemsOnSpinner(); // Spinner for project/service/training
        tp = new TimePick(); // call tmePick
        description=(EditText)findViewById(R.id.editTextWorkDescription);
        timeIn=(EditText)findViewById(R.id.TimeIn);
        timeOut=(EditText)findViewById(R.id.TimeOut);
        save=(Button)findViewById(R.id.saveButton);
        seekBar=(SeekBar)findViewById(R.id.seekBarPercentage);
        progressText=(TextView)findViewById(R.id.textProgress);
        progressText.setText("Covered:" + "" + seekBar.getProgress() + "/" + seekBar.getMax());

        if(getIntent().getExtras()!=null)
        {
            final String Project1=getIntent().getStringExtra("ReceiveProject");
            final String Description1 = getIntent().getStringExtra("ReceiveDescription");
            final int Progress1=getIntent().getIntExtra("ReceiveProgress",0);
            final String TimeIn1=getIntent().getStringExtra("ReceiveTimeIn");
            final String TimeOut1=getIntent().getStringExtra("ReceiveTimeOut");
            // project.setText(Project1);

            description.setText(Description1);
            timeIn.setText(TimeIn1);
            timeOut.setText(TimeOut1);
            seekBar.setProgress(Progress1);
           // Toast.makeText(this,Progress1,Toast.LENGTH_LONG).show();
            progressText.setText("Covered:" + "" + seekBar.getProgress() + "/" + seekBar.getMax());
        }

Solution

  • Instead of below line:

    i.putExtra("ReceiveProgress", ReceiveProgress[1].getProgress()); //cannot resolve getProgress
    

    Change it to below code in Activity A

    //checking array length if its greater than 1 then you can get value from index 1 
    if(ReceiveProgress.length > 1){
       i.putExtra("ReceiveProgress", Integer.parseInt(ReceiveProgress[1])); 
     }
    

    ReceiveProgress is string array and your sending it as string and as an integer and in Activity B you are fetching it as Integer.