【发布时间】:2013-01-09 16:11:12
【问题描述】:
我收到这个奇怪的错误:
R.id cannot be resolved
上线:
WebView myWebView = (WebView) findViewById(view.R.id.webview);
myWebView.loadUrl(s);
我尝试清理项目并重新启动它。 这是我的代码:
public class NewsActivity extends ListActivity {
public ReadXML ReadXML=new ReadXML();
public ArrayList<String> ynetList =new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for(int i=0;i<ReadXML.hadashotListItems.size();i++)
ynetList.add(ReadXML.hadashotListItems.get(i).title+"\n"+ReadXML.hadashotListItems.get(i).pubDate);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, ynetList));
// setContentView(R.layout.main);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// When clicked, show a toast with the TextView text
String s= ReadXML.hadashotListItems.get(position).link;
WebView myWebView = (WebView) findViewById(view.R.id.webview);
myWebView.loadUrl(s);
//
//Toast.makeText(getApplicationContext(((TextView)view).getText(),Toast.LENGTH_SHORT).show();
}
}
);
}}
我的 xml 代码是: list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="15sp" >
</TextView>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
感谢您的帮助!
【问题讨论】:
-
在父 Layout Container 中包含
xmlns:android就足够了。您不需要在其中包含每个标签。 -
每个问题请坚持一个问题。否则,当其他人回答这个问题时,他会完全混淆多个答案。如果您有多个问题,请提出不同的问题。
标签: android listactivity