【发布时间】:2020-04-04 12:29:25
【问题描述】:
现在我的代码是这样的:
private ImageButton nextButton;
private TextView textView;
private int stringIndex = 0;
private String[] dialog = {
"You: Hey, how are you?",
"She: I am fine and you?",
"You: I am fine as well!",
"She: Nice to meet you!"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_restaurant);
textView = findViewById(R.id.textView);
nextButton = findViewById(R.id.imageButton);
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view){
if (stringIndex == dialog.length-1){
stringIndex = 0;
textView.setText(dialog[stringIndex]);
} else {
textView.setText(dialog[++stringIndex]);
}
}
它工作正常,但困扰我的是字符串数组。我更喜欢将该对话框保存在文本文件中,并在单击该按钮时逐行读取。 我看到了一些关于资产和 FileReader/BuffedReader 的解决方案,但我被困住了,需要你的帮助!
【问题讨论】:
标签: java android text stream filereader