public class MainActivity extends Activity {
EditText etName;
TextView tvNum;
String res;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etName = (EditText) findViewById(R.id.etName);
tvNum = (TextView) findViewById(R.id.tvNum);
etName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if (!hasFocus) {
String str = etName.getText().toString();
String s[] = str.split("-");
tvNum.setText(s[1]);
//方法二
/*int num = str.indexOf("-");
if(num > 0)
{
res = str.subSequence(num + 1, str.length()).toString();
}
tvNum.setText(res);*/
}
}
});
}
}