Wednesday, October 10, 2012

EditView for Android: Combination of EditText and TextView

It is often that page of a particular informational content has 2 main objective, to view and edit at the same time, for instance, personal information page. The common solution for these 2 objectives is to have 2 views i.e. display view and edit view. Technically, there are usually 2 activities, one to display and one to edit the content, each of them has similar layout and similar coding as well. Moreover, when there is a change of the layout or additional fields, both activities have to be modified.

The root cause of such problem due to the technically, TextView and EditView only serving one purpose. TextView can be used to display data while EditView can be used to edit only. An idea to combine both together to have only single page to both display and edit the same content would beneficial to both developer and user. Less duplicate works for developer, maintenance would be come easier and user would have a more user friendly UI and experience by interact with only single place for both display and edit purpose. 

The idea of combining both display view and edit view is quite common for web application. However, android seems has no ready-to-use view available in the default framework. Hence, I developed a simple view called EditView, an combination of both TextView and EditText or simply Editable TextView (There is an editable attribute in TextView but I'm not sure how it works). 

A default EditView has an edit button next to an input/display field. Click on the edit button will toggle between edit mode and display mode. All the save and update to database or other storage files take place in that click. 


Also, it is often that there exist more than 1 field in a form and a better approach for multiple fields is to have master control button which will toggle the display/edit mode for all necessary fields. In this case, the edit button of EditView could be hidden.


I had many encounter of this display/edit problem and annoyed by the double work for both views so I decided to write a simple view for this problem. I hope this simple view could be handy in the display/edit view task for other Android developers as well.



No comments:

Post a Comment