Android - some basic control & resource operations

来源:互联网 发布:js if undefined 编辑:程序博客网 时间:2024/05/22 08:07

Android - some basic control & resource operations

  • get control by resource id
(Button)findViewById(R.id.btnMtFaberLine);
  • download population
dropdownDirection = (Spinner)findViewById(R.id.spinnerWelcome);String[] items = new String[]{"Entry","Exit"};ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items);dropdownDirection.setAdapter(adapter);
  • set textview text and bold
TextView textViewUserName = (TextView)findViewById(R.id.usernameTV);textViewUserName.setTypeface(null, Typeface.BOLD);textViewUserName.setText("User: " + username);
  • image view operation
ImageView img1 = (ImageView) findViewById(R.id.imageView1);img1.setImageDrawable(null);img1.setImageResource(R.drawable.check);
  • play audio
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.wrong);mp.start();
  • format datetime
SimpleDateFormat dtFormater = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss",        Locale.ENGLISH);dtFormater.format(new Date());
1 0