开发者

Populate EditText with value from database

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


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜