当前位置: 代码迷 >> Android >> 为何小弟我不能获取EditText中的内容?大侠们
  详细解决方案

为何小弟我不能获取EditText中的内容?大侠们

热度:104   发布时间:2016-05-01 21:09:33.0
为何我不能获取EditText中的内容?大侠们 。
//附部分代码
public class PickupActivity extends Activity {
private MusicInfo musicInfo;
private TextView musicName;
private Button sureButton;
private Button cancelButton;
private int starNums;
private String description;
private MusicInfoDbAdater musicInfoDbAdater = null;
private MyMusicInfo myMusicInfo; 
private MusicInfoDao infoDao;
private DatabaseHelper databaseHelper;
/*
  * (non-Javadoc)
  * 
  * @see android.app.Activity#onCreate(android.os.Bundle)
  */
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.pickup);
  Intent intent = getIntent();
  musicInfo = (MusicInfo)intent.getSerializableExtra("musicInfo");
  musicName = (TextView) findViewById(R.id.pickup_musicName);
  musicName.setText(musicInfo.getMusicName());
  final RatingBar starRatingBar = (RatingBar) findViewById(R.id.pickup_star);
  starNums = starRatingBar.getNumStars();
  final EditText descriptionEditText = (EditText) findViewById(R.id.pickup_description);
  description = descriptionEditText.getText().toString().trim();
  sureButton = (Button) findViewById(R.id.pickup_ok);
  cancelButton = (Button) findViewById(R.id.pickup_cancel);
  //绑定监听器
  sureButton.setOnClickListener(new SureButtonOnClickListener());
  cancelButton.setOnClickListener(new CancelButtOnClickListener());
}

class SureButtonOnClickListener implements OnClickListener {
  @Override
  public void onClick(View v) {
  infoDao = new MusicInfoDao(PickupActivity.this);
  infoDao.open();
  myMusicInfo = new MyMusicInfo();
  myMusicInfo.setDescription(description);
  myMusicInfo.setMusicName(musicInfo.getMusicName());
  myMusicInfo.setStar(starNums);
  long i = infoDao.insertToTable(myMusicInfo);
  if (i > 0) {
  showToast("成功录入信息");
  finish();
  } else {
  showToast("录入信息失败");
  finish();
  }
  }
}


------解决方案--------------------
楼主是要在交互的过程中获取EditText中的字符串吧,如果是这个意思的话,我想楼主的问题出在这里:
Java code
final EditText descriptionEditText = (EditText) findViewById(R.id.pickup_description);  description = descriptionEditText.getText().toString().trim();
  相关解决方案