This is very simple, just an input box, a button, a textview used to display the converted string, the button has an event, the use of visual interface to add, after all, it is very convenient!
Layout file Code:
1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:id= "@+id/linearlayout2"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 android:orientation= "vertical"7 Android:paddingbottom= "@dimen/activity_vertical_margin"8 Android:paddingleft= "@dimen/activity_horizontal_margin"9 Android:paddingright= "@dimen/activity_horizontal_margin"Ten Android:paddingtop= "@dimen/activity_vertical_margin" One Tools:context=". Mainactivity " > A - <LinearLayout - Android:layout_width= "Match_parent" the Android:layout_height= "Wrap_content" > - - <TextView - Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" - Android:text= "lowercase string:" /> + A <EditText at Android:id= "@+id/etl" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - Android:layout_weight= "1" - Android:ems= "Ten" > - in <Requestfocus/> - </EditText> to + </LinearLayout> - the <Button * Android:id= "@+id/bnt1" $ Android:layout_width= "Match_parent"Panax Notoginseng Android:layout_height= "Wrap_content" - Android:onclick= "Btnconvert_click" the Android:text= "Convert" /> + A <TextView the Android:id= "@+id/tvresult" + Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" $ Android:text= "Uppercase string:" /> $ - </LinearLayout>
Java files:
1 Packagecom.dc365.t1;2 3 ImportAndroid.os.Bundle;4 Importandroid.app.Activity;5 ImportAndroid.view.Menu;6 ImportAndroid.view.View;7 ImportAndroid.widget.EditText;8 ImportAndroid.widget.TextView;9 Ten Public classMainactivityextendsActivity { One A //variable *********************************************************************** - PrivateEditText ETL =NULL; - PrivateTextView result =NULL; the - //function *********************************************************************** - @Override - protected voidonCreate (Bundle savedinstancestate) { + Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); +Etl=(EditText) Findviewbyid (r.id.etl); Aresult=(TextView) Findviewbyid (r.id.tvresult); at } - - @Override - Public BooleanOncreateoptionsmenu (Menu menu) { - //inflate the menu; This adds items to the action bar if it is present. - //getmenuinflater (). Inflate (R.menu.main, menu); in return true; - } to + - Public voidBtnconvert_click (View v) the { *String s= ""; $s=Etl.gettext (). toString ();Panax Notoginsengs=s.touppercase (); -Result.settext ("Uppercase string:" +s); the } +}
Operating effect:
Android_ String Conversions