Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在不知道 idsetText()的情况下使用函数EditText,所以如果EditText应用程序中有三个,则命令setText()应该更改所有三个上的文本,我不会知道 id。
setText()
EditText
我打算使用这个命令:
EditText ed = (EditText) findView (something);
我不认为这很简单。有没有办法做到这一点?
您可以将onlyTextViews放在ViewGroup(ie LinearLayout) 中,然后像这样遍历他们的孩子。-
TextViews
ViewGroup
LinearLayout
for (int i = 0; i < containerView.getChildCount(); i ++) { View view = containerView.getChildAt(i); if (view instanceof TextView) { TextView textView = (TextView) view; textView.setText(yourText); } }