+----------------------------+ | Dog | +----------------------------+ | + name : String | | + breed : String | | + age : int | +----------------------------+ | + Dog(name: String, breed: | | String, age: int) | | + toString( ) : String | +----------------------------+On the layout, include 3 buttons, each of which adds specific Dog data to the arraylist. Also include a button that displays the list of dogs in the arraylist in a textview widget. Save the arraylist in a bundle that can be used to restore the arraylist when the app is destroyed due to being rotated.
Minimum Maximum Byte 1 Byte 2 Byte 3 code code point point One byte: U+0000 U+007F 0xxxxxxx Two bytes: U+0080 U+07FF 110xxxxx 10xxxxxx Three bytes: U+0800 U+FFFF 1110xxxx 10xxxxxx 10xxxxxxAns: Look up the Unicode code for € on the unicode.org website. The hex code is 20AC. Since 0800 <= 20AC <= FFFF, we use the 3 byte representation:
(a) Translate to binary: 2 0 A C 0010 0000 1010 1100 (b) Group bits into groups of 4, 6, and 6 bits: 0010 0000 1010 1100 --> 0010 000010 101100 (c) Prepend the UTF-8 bits 1110, 10, and 10. 0010 000010 101100 --> 11100010 10000010 10101100 (d) Group into groups of 4 bits and translate back to hex: 11100010 10000010 10101100 --> 1110 0010 1000 0010 1010 1100 --> E282ACCheck your answer. Copy and paste the Euro character € into Notepad or another editor that supports Unicode. Then display the hex dump of the file by invoking powershell and then entering the command
Format-Hex filename.txtIf you are on a Mac, which runs Unix, use the octal dump with the hex flag:
od -x filename.txt
private String[ ] words = {"zero", "one", "two", "three", "four"};
LinearLayout layout = findViewById(R.id.linear_layout);
final TextView txtWord = new TextView(this); final Button btnNextWord = new Button(this);
txtWord.setText(words[wordIndex++]); btnNextWord.setText("NEXT WORD");
txtWord.setTextSize( TypedValue.COMPLEX_UNIT_SP, 24); btnNextWord.setTextSize( TypedValue.COMPLEX_UNIT_SP, 24);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(50, 50, 0, 0); txtWord.setLayoutParams(params); btnNextWord.setLayoutParams(params);
layout.addView(txtWord); layout.addView(btnNextWord);
// Add onClick listener to button. btnNextWord.setOnClickListener( new View.OnClickListener( ) { @Override public void onClick(View view) { txtWord.setText( words[(wordIndex++ % numWords)]); } });
@Override public void onDraw(Canvas c) { Paint p = new Paint( ); p.setColor(Color.RED); c.drawCircle(100, 120, 30, p); }
public MyView(Context context) { super(context); }
MyView mv = new MyView(this); LinearLayout layout = findViewById(R.id.layout); layout.addView(mv);