Android字符小写转大写,大写转小写

时间:2022-03-23 09:10:59

有些需求中可能对输入的字符不论大小写,即输入大小写字符都可以,网上找了下资料,有大神写的算法,个人感觉根据

需求来,能简单就简单来,哈哈


Android字符小写转大写,大写转小写Android字符小写转大写,大写转小写

比较简单,把输入的小写转大写,大写转小写,就调用一个方法即可:

public class DemoActivity extends Activity {

private Button btn1,btn2;
private EditText edit1,edit2;

AlertDialog.Builder builder;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.demo);

findView();

builder = new AlertDialog.Builder(this);
builder.setTitle("提示");
/**
* 小写转大写
*/
btn1.setOnClickListener(new OnClickListener() {


@SuppressLint("DefaultLocale")
@Override
public void onClick(View v) {
//获取输入的字符串内容
String inputData1 = edit1.getText().toString().trim().toUpperCase();
builder.setMessage(inputData1);
builder.show();


}
});

/**
* 大写转小写
*/
btn2.setOnClickListener(new OnClickListener() {


@SuppressLint("DefaultLocale")
@Override
public void onClick(View v) {
String inputData2 = edit2.getText().toString().trim().toLowerCase();
builder.setMessage(inputData2);
builder.show();

}
});



}

private void findView() {
btn1 = (Button) findViewById(R.id.btn1);
btn2 = (Button) findViewById(R.id.btn2);
edit1 = (EditText) findViewById(R.id.editText1);
edit2 = (EditText) findViewById(R.id.editText2);

}

}

哈哈,就这样

代码地址:http://download.csdn.net/detail/sunjianhua360/9400276