基本上,我试图从 Api 回调响应中获取一些值,然后将这些值分配给我的一些成员变量,但似乎程序每次都必须运行我的 getPatientRecord() 方法才能进入我的调用,这是我以前从未遇到过的。日志输出结果是: 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条经验 获得超4个赞
我看不出问题。调用在retrievePatientByUuid其中由调用完成getPatientRecord。所以是的,你必须通过getPatientRecord。调用是异步的。您应该在回调中设置 TextViews :
tvName.setText(pName);
tvGender.setText(pGender);
tvBirthDate.setText(pBirthdate);
tvAddress.setText(pAddress);
添加回答
举报
0/150
提交
取消