我正在尝试将数据添加到回收器视图适配器,但 getStringExtra 始终为空。由于我不是最有经验的程序员,我可能在我所做的事情中犯了一个关键的缺陷。
首先被称为:
public void addItem(View view) {
Intent otherOne = new Intent(this, Main2Activity.class);
startActivity(otherOne);
Intent intent = getIntent();
String subjectString = intent.getStringExtra("subject");
String detailsString = intent.getStringExtra("details");
String dateString = intent.getStringExtra("date");
Data dataToAdd = new Data(
subjectString,
detailsString,
dateString);
mData.add(dataToAdd);
Log.d(TAG, dateString + "might have workedlol");
// Update adapter.
mAdapter.addItem(mData.size()-1, dataToAdd);
}
在 MainActivity2 中调用的内容:
public void setData(View view){
inputSubject = (EditText) (findViewById(R.id.editTextSubject));
String stringSubject = inputSubject.getText().toString();
inputDetails = (EditText) findViewById(R.id.editTextDetails);
String stringDetails = inputDetails.getText().toString();
inputDate = (EditText) findViewById(R.id.editTextDate);
String stringDate = inputDate.getText().toString();
Intent intent = new Intent(this, PlannerActivity.class);
intent.putExtra("subject", stringSubject.toString());
Log.d(TAG, stringDate + "might have worked");
intent.putExtra("details", stringDetails.toString());
intent.putExtra("subject", stringDate.toString());
startActivity(intent);
}