0
如何將我的ListView的每一行中的WebView設置爲相應的url?目前,我有這樣的語句來獲得數據:Android:爲ListView中的每一行設置WebView
public void getTweets(String selection) {
String formatedcat = selection.toLowerCase();
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions
.getJSONfromURL("http://mysite.com/twitter.php);
try {
JSONArray category = json.getJSONArray(formatedcat);
for (int i = 0; i < category.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject c = category.getJSONObject(i);
map.put("id", String.valueOf(i));
String url = c.getString("image");
map.put("name",
c.getString("fullName") + "\n(#" + c.getString("name")
+ ") ");
map.put("text",c.getString("text"));
map.put("timestamp", c.getString("timestamp"));
mylist.add(map);
WebView mWebView;
mWebView = (WebView) findViewById(R.id.lvicon);
//mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.list,
new String[] { "name", "text", "timestamp"}, new int[] { R.id.item_title,
R.id.item_subtitle, R.id.timestamp});
setListAdapter(adapter);
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
m_ProgressDialog.dismiss();
}
我的列表視圖行中的XML是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="7dp">
<WebView android:id="@+id/lvicon" android:layout_width="52dp"
android:layout_height="52dp" android:layout_marginRight="6dip"
/>
<TextView android:id="@+id/item_title" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:textColor="#010002" android:textStyle="bold"
android:padding="2dp" android:textSize="18dp" android:layout_toRightOf="@+id/lvicon" />
<TextView android:id="@+id/item_subtitle" android:textColor="#010002" android:autoLink="web"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/item_title"
android:padding="2dp" android:textSize="13dp" />
<TextView android:id="@+id/timestamp" android:textColor="#010002"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/item_subtitle"
android:padding="1dp" android:textSize="10dp" android:gravity="right"/>
</RelativeLayout>
從調試例外似乎當獲取到WebView的ID關聯扔。
找到我使用的是SimpleAdapter,不是嗎? – Nick
啊,是的,但只有部分方法,將'adapter'的類型改爲SimpleAdapter,然後設置你的'ViewBinder'。 –