MainActivity는 아래입니다.
package com.example.lim.wordscore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MainActivity extends AppCompatActivity {
EditText editText; //전역변수 설정
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
String getEdit = editText.getText().toString();
public void wordScore(View v) {
int sum = 0;
for(int i=0; i<getEdit.length(); i++) {
char ch = getEdit.charAt(i);
int n = (int)ch - (int)'a' + 1;
sum += n;
}
Toast.makeText(getApplicationContext(), sum + "점 입니다.", Toast.LENGTH_LONG).show();
}
}
activity_main은 아래입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lim.wordscore.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Wordscore Game"
android:textStyle="italic"
android:textSize="36sp"
android:textColor="#000000" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Insert English word here."/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Score" />
</LinearLayout>
왜 실행이 안 되는지 모르겠습니다.
이유를 알아야 뭘 배우든 말든 할 텐데..