Android_字串轉換

來源:互聯網
上載者:User

標籤:

       這個很簡單,只是一個輸入框,一個按鈕,一個TextView用來顯示轉換後的字串,按鈕有一個事件,使用可視化操作介面下添加的,畢竟很方便嘛!

布局檔案代碼:

 1 <LinearLayout xmlns: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"10     android:paddingTop="@dimen/activity_vertical_margin"11     tools:context=".MainActivity" >12 13     <LinearLayout14         android:layout_width="match_parent"15         android:layout_height="wrap_content" >16 17         <TextView18             android:layout_width="wrap_content"19             android:layout_height="wrap_content"20             android:text="小寫字串:" />21 22         <EditText23             android:id="@+id/etL"24             android:layout_width="wrap_content"25             android:layout_height="wrap_content"26             android:layout_weight="1"27             android:ems="10" >28 29             <requestFocus />30         </EditText>31 32     </LinearLayout>33 34     <Button35         android:id="@+id/bnt1"36         android:layout_width="match_parent"37         android:layout_height="wrap_content"38         android:onClick="btnConvert_Click"39         android:text="轉        換" />40 41     <TextView42         android:id="@+id/tvResult"43         android:layout_width="wrap_content"44         android:layout_height="wrap_content"45         android:text="大寫字串:" />46 47 </LinearLayout>

Java檔案:

 1 package com.dc365.t1; 2  3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6 import android.view.View; 7 import android.widget.EditText; 8 import android.widget.TextView; 9 10 public class MainActivity extends Activity {11  12     //變數***********************************************************************13     private EditText etl = null;14     private TextView result = null;15     16     //函數***********************************************************************17     @Override18     protected void onCreate(Bundle savedInstanceState) {19         super.onCreate(savedInstanceState);20         setContentView(R.layout.activity_main);21         etl=(EditText)findViewById(R.id.etL);22         result=(TextView)findViewById(R.id.tvResult);23     }24 25     @Override26     public boolean onCreateOptionsMenu(Menu menu) {27         // Inflate the menu; this adds items to the action bar if it is present.28         //getMenuInflater().inflate(R.menu.main, menu);29         return true;30     }31     32     33     public void btnConvert_Click(View v)34     {35         String s="";36         s=etl.getText().toString();37         s=s.toUpperCase();38         result.setText("大寫字串:"+s);39     }40 }

運行效果:

Android_字串轉換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.