Download presentation
Presentation is loading. Please wait.
Published byRoxanne Boyd Modified over 8 years ago
1
로봇 모션 편집기 4/4 UNIT 25 로봇 SW 콘텐츠 교육원 조용수
2
학습 목표 에디트 텍스트를 사용할 수 있다. 아이템을 삭제할 수 있다. 아이템을 편집할 수 있다. 2
3
TextView 에디트 텍스트 3 Object View EditText
4
XML 속성 : inputType none text, textUri, textEmailAddress number, numberSigned, numberDecimal phone datetime, date, time textPassword 4 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="none" />
5
XML 속성 : inputType 5 nonetexttextUritextEmailAddress
6
XML 속성 : inputType 6 numbernumberSignednumberDecimalphone
7
XML 속성 : inputType 7 datetimedatetimetextPassword
8
XML 속성 : hint 8 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" android:hint="@string/hint" />
9
로봇 움직이기 9 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <RadioGroup android:id="@+id/action" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:checkedButton="@+id/forward"> <RadioButton android:id="@id/forward" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/forward" /> <RadioButton android:id="@+id/turn_left" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/turn_left" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/speed" /> <EditText android:id="@+id/etSpeed" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="number" android:hint="@string/hint" />
10
로봇 움직이기 10 private final int DIALOG_ADD = 1; View layout = null; RadioGroup radioGroup = null; CheckBox checkBox = null; EditText etSpeed = null; private void ShowDialog(int id, Bundle bundle) { switch(id) { case DIALOG_ADD: layout = View.inflate(this, R.layout.action, null); radioGroup = (RadioGroup)layout.findViewById(R.id.rgAction); etSpeed = (EditText)layout.findViewById(R.id.etSpeed); etSpeed.setText("50"); new AlertDialog.Builder(this).setTitle("Add Actions").setIcon(R.drawable.ic_launcher).setView(layout).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub int action = radioGroup.getCheckedRadioButtonId() == R.id.rbforward? Action.FORWARD: Action.TURN_LEFT; int speed = 0; try{ speed = Integer.parseInt(etSpeed.getText().toString()); } catch (NumberFormatException ne) { } actions.add(new Action(action,speed)); adapter.notifyDataSetChanged(); } }).setNegativeButton("Cancel", null).setCancelable(false).show(); break;
11
아이템 편집 11 private static final class Action { int id; int icon; int name; int speed; private final int[] icons = new int[] { R.drawable.forward_on, R.drawable.left_on }; private final int[] names = new int[] { R.string.forward, R.string.turn_left }; static final int FORWARD = 0; static final int TURN_LEFT = 1; Action(int id, int speed) { this.id = id; this.icon = icons[id]; this.name = names[id]; this.speed = speed; } void update(int id, int speed) { this.id = id; this.icon = icons[id]; this.name = names[id]; this.speed = speed; }
12
아이템 편집 12 public class MainActivity extends RobotActivity implements View.OnClickListener { private Button startButton; private Button stopButton; private final ArrayList actions = new ArrayList (); private ActionListAdapter adapter; private Device leftWheelDevice; private Device rightWheelDevice; private int time; private int index; private boolean running; private static final int DIALOG_ADD = 1; private static final int DIALOG_EDIT = 2;
13
아이템 편집 13 case DIALOG_EDIT: final int position = bundle.getInt("Position"); final Action item = actions.get(position); layout = View.inflate(this, R.layout.action, null); radioGroup = (RadioGroup)layout.findViewById(R.id.rgAction); if(item.id == Action.FORWARD){ radioGroup.check(R.id.rbforward); } else { radioGroup.check(R.id.rbTurnLeft); } checkBox = (CheckBox)layout.findViewById(R.id.ckSpeed); checkBox.setVisibility(View.GONE); etSpeed = (EditText)layout.findViewById(R.id.etSpeed); etSpeed.setText("" + item.speed); …
14
아이템 갱신 14 new AlertDialog.Builder(this).setTitle("Edit Actions").setIcon(R.drawable.ic_launcher).setView(layout).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub int action = radioGroup.getCheckedRadioButtonId() == R.id.rbforward? Action.FORWARD: Action.TURN_LEFT; int speed = 0; try{ speed = Integer.parseInt(etSpeed.getText().toString()); } catch (NumberFormatException ne) { } item.update(action, speed); adapter.notifyDataSetChanged(); } }).setNegativeButton("Cancel", null).setCancelable(false).show();
15
아이템 선택 15 listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { // TODO Auto-generated method stub Bundle bundle = new Bundle(); bundle.putInt("Position", position); ShowDialog(DIALOG_EDIT, bundle); } });
16
로봇 조정기 완성 16 2 가지 방향 추가 - 후진 - 우회전
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.