내 for
루프에 어떤 문제가 있다고 말해 줄 수 있습니까? 나는이 프로그램이 텍스트의 모든 단어를 검사하여 그것을 확인하기를 원한다. 예를 들어 텍스트의 문장이 "nona chan"이라면 단어별로 단어를 검색하고 'nona'라는 단어가 'good'이라는 단어로 바뀌면 다음 단어로 이동하십시오.텍스트를 스캔하고 일치하는 경우 바꾸기
package com.example.split;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText te1 = (EditText) findViewById(R.id.t1);
final EditText te2 = (EditText) findViewById(R.id.t2);
final Button b = (Button) findViewById(R.id.b1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//imva.setImageResource(R.id.b1);
String t = te1.getText().toString();
String[] t1 = t.split(" ");
for (int i = 0; i <= t1.length; i++) {
do {
if (t1[i].equals("nona")) {
String v1 = t1[i];
String v2 = " good ";
String a = v1.replace(v1, v2);
te2.setText(a);
} else if (t1[i].equals("chan")) {
String v1 = t1[i];
String v3 = " job ";
String a = v1.replace(v1, v3);
te2.setText(a);
}
} while (te1.length() != 0);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
변경 전 <= t1.length :
또한,이 라인은 아무것도하지 않습니다이로 대체 할 수 있도록
는 것은 단순히
Pragnani
a
에v2
설치 i