我正在尝试从另一个生成的文本文件中导入文本Activity.生成的文本文件由String ArrayList仅包含数字和由Android生成的其他随机文本组成.当我从文件中导入文本时,我正在使用a BufferedReader并将readLine()每个新数字转换为Integer ArrayList.我正从文本文件中删除任何非数字值,而在另一个Activity中生成的数字将被"\n"拆分.
我面临的问题是Android在加载时会崩溃Activity.我把原因缩小到了Integer.parseInt().
我的代码如下:
ArrayList<Integer> lines = new ArrayList<Integer>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
File file = new File(getFilesDir(), "test_file.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(file));
while (br.readLine() != null) {
String text = (br.readLine()).replaceAll("[^0-9]+","").trim();
Integer number = Integer.parseInt(text);
lines.add(number);
}
} catch (IOException e) {
}
TextView tv = (TextView) findViewById(R.id.helptext);
int max = 0, min = 100;
double total …Run Code Online (Sandbox Code Playgroud) 我有动态改变文本的问题TextView在PopupWindowAndroid中.我已使用a 引用了TextView内部元素,但文本未更新.任何帮助将非常感谢!:)PopupWindowLayoutInflaterViewGroup
我的代码如下:
private void popupWindow() {
try {
LayoutInflater inflater = (LayoutInflater) SwingSpeed.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_recording,
(ViewGroup) findViewById(R.id.popup_element));
pw = new PopupWindow(inflater.inflate(R.layout.popup_recording,
null, false), 480, 800, true);
pw.showAtLocation(findViewById(R.id.swingspeed), Gravity.CENTER, 0,
0);
recording_text = (TextView) layout
.findViewById(R.id.recording_text);
recording_text.setText("Recording"); //Update the TextView
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)