我正在制作获取最后推文的Android应用程序,并将配置文件图像+状态文本拉到表中。 我试过了:
private void setTwitTable() {
List<Status> statuses = null;
try {
statuses = getTimeLine();
} catch (TwitterException te) {
Log.d(TAG, "Failed to get timeline: " + te.getMessage());
return;
}
TableLayout twit_tl = (TableLayout) findViewById(R.id.twitsTableLayout);
for (Status status : statuses) {
User user = status.getUser();
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
ImageView iv = new ImageView(this);
try {
iv.setBackgroundDrawable(getDrawableFromUrl(user.getProfileImageURL(), "ProfileImage"));
Log.d(TAG, "Image Good!");//debug
} catch (MalformedURLException e) {
Log.d(TAG, "MalformedURLException: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "IOException: " + e.getMessage());
}
iv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tr.addView(iv);
twit_tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
}
}
private List<Status> getTimeLine() throws TwitterException {
// gets Twitter instance with default credentials
Twitter twitter = new TwitterFactory().getInstance();
List<Status> statuses = twitter.getUserTimeline(USER);
return statuses;
}
Drawable getDrawableFromUrl(java.net.URL url, String src_name)
throws java.net.MalformedURLException, java.io.IOException {
return Drawable.createFromStream(
((java.io.InputStream) url.getContent()),
src_name);
}
但我只看到黑色背景 - 没有别的。没有图像。没有桌子。