晚上好。
我有这样的活动。在 handleMessage 中,我可以访问 largeText 字段并且可以更改它,但是我无法使用 stringLinks 字段或其他不是 UI 元素的字段(如 TextView、Button、EditText 等)。如何添加到 stringLinks ?
public class AboutUsActivity extends Activity {
Handler h;
TextView largeText;
List<String> stringLinks;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
stringLinks = new ArrayList<String>();
largeText = (TextView) findViewById(R.id.textView1);
h = new Handler() {
public void handleMessage(android.os.Message msg) {
HtmlParser parser;
StringBuilder result = new StringBuilder();
try {
parser = new HtmlParser(String.valueOf(msg.getData()));
List<TagNode> links = parser.getContentByClassName("ab");
for (Iterator<TagNode> iterator = stringLinks.iterator(); iterator
.hasNext();) {
TagNode divElement = (TagNode) iterator.next();
result.append(divElement.getText().toString());
}
} catch (Exception e) {
e.printStackTrace();
}
largeText.setText(newhtml); //Work
stringLinks.add(newhtml); //doesn't work
}
};
MyHttpClientUsage connect = new MyHttpClientUsage(h);
try {
connect.getInfoAbout();
} catch (HttpException e) {
e.printStackTrace();
}
}
}