基础:用android开发的ASCII码转换器
剛學android一個月,嘗試寫了個簡單的ASCII碼轉換器,核心代碼如下:
?
?? package wyf.jc;??? ??? ??? ??? //聲明包語句
import android.app.Activity;??? //引入相關類
import android.os.Bundle;??? ??? //引入相關類
import android.view.View;
import android.widget.Button;??? //引入相關類
import android.widget.EditText;??? //引入相關類
public class AbsoluteActivity extends Activity {
??? @Override
??? public void onCreate(Bundle savedInstanceState) {??? //重寫onCreate方法
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.main);??? ??? ??? ??? ??? //設置當前屏幕
??????? final Button OkButton = (Button) findViewById(R.id.Button01);??? ??? //獲取確定按鈕對象
??????? final Button resetButton = (Button) findViewById(R.id.Button02);
??????? final EditText str1=(EditText)findViewById(R.id.EditText01);??? ??? ??? //獲取第一個數文本框對象
??????? final EditText result=(EditText)findViewById(R.id.EditText02);??? ??? ??? //獲取第二個數文本框對象
??????? OkButton.setOnClickListener(//OnClickListener為View的內部接口,其實現者負責監聽鼠標點擊事件
??????? ??? ??? new View.OnClickListener(){
??????? ??? ??? ??? public void onClick(View v){ ??? ??? ??? ??? ??? //重寫onClick方法
??????? ??? ??? ??? ??? String str=str1.getText().toString(); //獲取第一個數文本框的值
??????? ??? ??? ??? ??? byte[] cc = str.getBytes();
??????? ??? ??? ??? ??? int a=(int)cc[0];
??????? ??? ??? ??? ??? result.append(a+";");
??????? ??? ??? ??? }
??????? ??? ??? });
??????? resetButton.setOnClickListener(//OnClickListener為View的內部接口,其實現者負責監聽鼠標點擊事件
??????????????? new View.OnClickListener(){
??????????????? ??? public void onClick(View v){ ??? ??? //重寫onClick方法
??????????????? ??? ??? str1.setText("");??? ??? ??? ??? //清空文本框內容
??????????????? ??? ??? result.setText("");
??????????????? ??? }
??????????????? });
??? }
}
效果圖:
總結
以上是生活随笔為你收集整理的基础:用android开发的ASCII码转换器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 华为鸿蒙消费者,王成录谈鸿蒙挑战和华为消
- 下一篇: 能设值多个rowkey吗_顶楼送了露台,