0
私は、異なるテキストを持つクラスを作成してユーザーに伝えたいと考えています。私はユーザーがそれをクリックするたびにtextViewを変更したonclickListenerで構成されたクラスを作った。しかし、それはプログラムim buildindのために面倒な方法です。私はそれがクラスや何かを作ることができるより簡単な方法かどうかを知りたいのですが、何千ものラインのonclickリスナーを作るのではなく、ユーザーに話すことができます。ここに、私のコードがどのように見えるかの小さなスニペットがあります。androidのダイアログクラスを作成するには
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class DorothyTalk extends Activity{
TextView text1;
EditText edit;
Button respond;
private String name;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.dorothydialog);
text1 = (TextView)findViewById(com.fttech.da.R.id.dialog);
edit = (EditText)findViewById(com.fttech.da.R.id.repsond);
respond = (Button)findViewById(com.fttech.da.R.id.button01);
Talk();
}
private void Talk(){
text1.setText("Welcome what is your name?");
respond.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
name = edit.getText().toString();
text1.setText("Nice to meet you "+name);
respond.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1.setText("");
}
});
}
});
}
}
これは私がやりたくないことです。これは長い時間がかかり、より多くのリソースを使い果たします。私はこれを行うより良い方法があるように感じる。もし誰かが助けてください知っている。
私のコードを使用して、私があなたが何をすべきだと思うかの例を教えてください。ありがとう。 – theITRanger22