Populate EditText with value from database

耗尽温柔 提交于 2019-12-11 03:39:51

问题


In my Android application I have a TextView with an EditText. I want to prepopulate the EditText with the last value entered, which is stored in the SQLite database?


回答1:


This should not be so hard I think:

public void onCreate(Bundle savedState) {
    EditText editText = (EditText) findViewById(R.id.my_edittext);
    String value = // Query your 'last value'.
    editText.setText(value);
}

If you want to learn more about SQLite database storage, read this article in Android document.




回答2:


Assign an edittext to it's resource ID via getViewById(R.id.xxxx)

then do a SQLite query for the highest PID...

then pull theString you're looking for out of the result cursor...

assign that via editTextId.setText(theString);

be sure to enclose it in a try/catch and assign the edittext to some arbitrary default value if the db exec fails due to no entries in the table.




回答3:


I have done this By using Spinner inside EditText.

Take EditText and Spinner inside a RelativeLayout retrieve data from DB and assign those values to the spinner.

By using OnItemSelectedListener to the spinner u can assign the selected values to ur EdiText.



来源:https://stackoverflow.com/questions/5921386/populate-edittext-with-value-from-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!