基本上,我試圖從 Api 回調(diào)響應中獲取一些值,然后將這些值分配給我的一些成員變量,但似乎程序每次都必須運行我的 getPatientRecord() 方法才能進入我的調(diào)用,這是我以前從未遇到過的。日志輸出結(jié)果是: viewPatient: paitient method viewPatient: secondHello worldnullnull 100SN9 - David Hello HMH 1971-08-09這是我的代碼:public class ViewPatientRecord extends AppCompatActivity{TextView tvName, tvGender, tvBirthDate, tvAddress;String pGender, pAddress, pBirthdate;String pName = "Hello world";Patient myPatient;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_patient_record); tvName = findViewById(R.id.tvFullName); tvGender = findViewById(R.id.tvGender); tvBirthDate = findViewById(R.id.tvDb); tvAddress = findViewById(R.id.tvAddress); myPatient= new Patient(); try { getPatientRecord(); } catch (InterruptedException e) { e.printStackTrace(); }}private void getPatientRecord() throws InterruptedException { SharedPreferences myPre = getSharedPreferences("PatientRecord", MODE_PRIVATE); if(myPre.getString("uuid",null)!=null){ retrievePatientByUuid(myPre.getString("uuid",null)); Log.d("viewPatient", "second"+pName+pGender+pBirthdate); tvName.setText(pName); tvGender.setText(pGender); tvBirthDate.setText(pBirthdate); tvAddress.setText(pAddress); }else{ Toast.makeText(ViewPatientRecord.this, "Something went wrong, please contact the administrator for help!", Toast.LENGTH_SHORT).show(); }}
1 回答

慕萊塢森
TA貢獻1810條經(jīng)驗 獲得超4個贊
我看不出問題。調(diào)用在retrievePatientByUuid其中由調(diào)用完成getPatientRecord。所以是的,你必須通過getPatientRecord。調(diào)用是異步的。您應該在回調(diào)中設置 TextViews :
tvName.setText(pName);
tvGender.setText(pGender);
tvBirthDate.setText(pBirthdate);
tvAddress.setText(pAddress);
添加回答
舉報
0/150
提交
取消