嗨,我正在使用 listview onclick load webview 这工作正常。
我的问题现在是在 onclick listview 之前我使用默认网页加载到 webview 这不起作用...
这是我的代码
webview=(WebView)app.findViewById(R.id.webView);
webview.loadUrl("http://google.com");//this is my default webview before onclick the list view
上述默认网址未加载...
ListView listView = (ListView) menu.findViewById(R.id.list);
initListView(listView);
public void initListView(final ListView listView) {
// By using setAdpater method in listview we an add string array in list.
ArrayList<ItemDetails> image_details = GetSearchResults();
listView.setAdapter(new ItemListBaseAdapter(this, image_details));
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = listView.getItemAtPosition(position);
ItemDetails obj_itemDetails = (ItemDetails)o;
String msg =obj_itemDetails.getName();
try{
if(null!=webview){
webview.removeAllViews();
}
if(msg.equalsIgnoreCase("a")){
webview.loadUrl("http://example.com");
}else if(msg.equalsIgnoreCase("b")){
webview.loadUrl("http://example.com");
}else if(msg.equalsIgnoreCase("c")){
webview.loadUrl("http://example.com");
}else if(msg.equalsIgnoreCase("d")){
webview.loadUrl("http://e.com");
}else if(msg.equalsIgnoreCase("e")){
webview.loadUrl("http://f.com");
}else{
webview.loadUrl("http://example.com");
}
}catch (Exception e) {
Toast.makeText(HorzScrollWithListMenu.this,e.toString(),Toast.LENGTH_LONG).show();
e.printStackTrace(System.out);
}
}
});
}
我的 onCreate 代码部分
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater inflater = LayoutInflater.from(this);
scrollView = (MyHorizontalScrollView) inflater.inflate(R.layout.horz_scroll_with_list_menu, null);
setContentView(scrollView);
menu = inflater.inflate(R.layout.horz_scroll_menu, null);
app = inflater.inflate(R.layout.horz_scroll_app, null);
webview=(WebView)app.findViewById(R.id.webView);
webview.loadUrl("http://google.com");
请让我知道我的代码出了什么问题。?