如何在另一个 class 中显示 seekBar 值?

How to show the seekBar value in another class?

我在 Activity A 中有两个列表。 listView 中的值来自 Activity B。单击列表时,它应该去 Activity B.

A中的Progress值,其实是从seekBar中获取的

假设第一个列表被点击,seekBar 应该显示 36 而不是 0 !这是我到目前为止尝试过的。

Activity一个

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

而不是下面一行:

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

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

ReceiveProgressstring array 并且您将其作为 stringinteger 发送,并且在 Activity B 中您正在获取它作为 Integer.

如果你想在某一点显示seekbar进度,你需要设置seekbar.setprogress(required value),如果你想测量seekbar值,你可以添加seekbar监听器每一点。 将 i.putExtra("ReceiveProgress", ReceiveProgress[1].getProgress()); 从 activity A 发送到 B 并在 B 中设置 seekbar.setprogresss(Integer.parseInt(ReceiveProgress[1].getProgress())).

希望对您有所帮助。