2015-11-30 52 views
0

我有兩個列表活動A。列表視圖中的值從活動B獲得。當列表被點擊時,它假設去活動B如何在另一個類中顯示seekBar值?

enter image description here

對於A中的進步價值,它實際上從搜索條得到。

假設第一個列表被點擊了,seekBar應該顯示36而不是0!這是我到目前爲止嘗試過的。

enter image description here

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

活動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()); 
     } 
+0

您只想要'seekbar'值或希望顯示'seekbar'進展到您正在獲取的值。 – Pankaj

+0

@Clairvoyant我想要顯示'seekbar進度' – John

+0

您是否添加了'setOnSeekBarChangeListener'? – Jas

回答

1

代替下面行:

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

其更改爲下面的代碼在活動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和您的發送它作爲string並作爲integerActivity B你取它作爲Integer

+0

感謝您的回答,但getProgress()仍然無法解析 – John

+0

已更新我的回答 – Pankaj

+0

檢查「ReceiveProgress」數組是否具有值'36'在索引1或不是。否則檢查索引0的值。 – Pankaj

0

您需要設置seekbar.setprogress(要求的值),如果你想在一個點來顯示搜索條的進步,如果你要測量的每一點seekbar值可以添加seekbar監聽器。 發送i.putExtra("ReceiveProgress", ReceiveProgress[1].getProgress());從活動A到B和B,設置seekbar.setprogresss(Integer.parseInt(ReceiveProgress[1].getProgress()))

希望它有幫助。

+0

沒有運氣。 getProgress無法解析 – John

相關問題