I would like to make a class that has different text to say to a user. I made a class that was composed of an onclickListener that changed the textView every time the user clicks it. But that is wayyy to tedious for the program im buildind. I would like to know if it is a easier way i can make a class or something that can just speak to the user instead of making thousands of lines of onclick listeners. Here's a small snippet of what my code looks like now.
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(co开发者_运维问答m.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("");
}
});
}
});
}
}
This is what i dont want to do.. This will take way to long and use up more resources. i feel like there is a better way of doing this. If anyone knows please help.
Just create an array of text lines to display and store the index of the next one. You will need just one OnClickListener which shows the next text and increments the index.
精彩评论