比较TextView的内容可以通过以下方法实现:
TextView textView1 = findViewById(R.id.text_view1);
TextView textView2 = findViewById(R.id.text_view2);
String text1 = textView1.getText().toString();
String text2 = textView2.getText().toString();
if (text1.equals(text2)) {
// TextView的内容相同
} else {
// TextView的内容不同
}
TextView textView1 = findViewById(R.id.text_view1);
TextView textView2 = findViewById(R.id.text_view2);
int num1 = Integer.parseInt(textView1.getText().toString());
int num2 = Integer.parseInt(textView2.getText().toString());
if (num1 == num2) {
// TextView的内容相同
} else {
// TextView的内容不同
}
TextView textView1 = findViewById(R.id.text_view1);
TextView textView2 = findViewById(R.id.text_view2);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = dateFormat.parse(textView1.getText().toString());
Date date2 = dateFormat.parse(textView2.getText().toString());
if (date1.compareTo(date2) == 0) {
// TextView的内容相同
} else {
// TextView的内容不同
}
以上是几种常见的比较TextView内容的方法,根据具体的需求选择适合的方法进行比较。
上一篇:比较特殊字符在Python中
下一篇:比较特征提取器(或比较对齐图像)