Java TextView没有';不要改变它的文本

Java TextView没有';不要改变它的文本,java,android,textview,Java,Android,Textview,您好,我对TextView有问题。这是我的密码 final TextView username = (TextView) _v.findViewById(R.id.username); final LinearLayout linear7 = (LinearLayout) _v.findViewById(R.id.linear7); final TextView date = (TextView) _v.findViewById(R.id.date); final TextView msg =

您好,我对TextView有问题。这是我的密码

final TextView username = (TextView) _v.findViewById(R.id.username);
final LinearLayout linear7 = (LinearLayout) _v.findViewById(R.id.linear7);
final TextView date = (TextView) _v.findViewById(R.id.date);
final TextView msg = (TextView) _v.findViewById(R.id.msg);
final TextView username2 = (TextView) _v.findViewById(R.id.username);
final LinearLayout linear72 = (LinearLayout) _v.findViewById(R.id.linear7);
final TextView date2 = (TextView) _v.findViewById(R.id.date);
final TextView msg2 = (TextView) _v.findViewById(R.id.msg);
final LinearLayout linear999 = (LinearLayout) _v.findViewById(R.id.linear999);
final LinearLayout linear9992 = (LinearLayout) _v.findViewById(R.id.linear9992);

username.setText(map1.get((int)_position).get("name").toString());
msg.setText(map1.get((int)_position).get("msg").toString());
date.setText(map1.get((int)_position).get("date").toString());
username2.setText(username.getText().toString());
msg2.setText(msg.getText().toString());
date2.setText(date.getText().toString());

如您所见,username2应该与username具有相同的文本。但是,它只有我在designer中为它提供的文本。请帮助。

我认为您不能更改文本,因为您已将其声明为最终变量。您需要将此代码块声明为final的代码块位于什么上下文中。没有我的第一个建议就试试吧

final TextView username = (TextView) _v.findViewById(R.id.username);
final TextView username2 = (TextView) _v.findViewById(R.id.username);

它们具有相同的视图id。您必须更改用户名2视图id。

查看您的id
TextView
它是相同的。将其更改为连接第二个
TextView

 final TextView msg = (TextView) _v.findViewById(R.id.msg);

 final TextView msg2 = (TextView) _v.findViewById(R.id.msg); <--- change this ID
final TextView msg=(TextView)\u v.findViewById(R.id.msg);

最终文本视图msg2=(文本视图)\ v.findViewById(R.id.msg) 我只是将两个不同用户(Maxitors和Mike)提到的两个正确问题合并为一个答案:

这两对的TextView是相同的元素

  • Username和Username2有一个id R.id.Username
  • msg和msg2有一个id R.id.msg
这使它们在您对它们进行函数调用时引用相同的元素。例如,将username2的文本设置为username的文本不会产生明显的效果,因为您只需将元素R.id.username的文本设置为自身


要解决此问题,您需要将Username2和msg2分配给正确的id,不管它们是什么。(查看您的命名方案,我怀疑它们是R.id.username2和R.id.msg2)

谢谢。我刚刚注意到我是如此愚蠢;P但是感谢您的快速回复^^^文本没有声明为最终变量,只有
TextView
TextView
作为最终版本没有问题。请注意,您在用户名、消息、linear7和日期上也犯了同样的错误