java - R cannot be resolved (XML issue but cannot find it) -
see bottom things have tried. gives me error anywhere r mentioned understand it, means there error in xml. cannot find anywhere though.
androidlistviewcursoradaptoractivity
package com.example.location_deals; import android.app.activity; import android.database.cursor; import android.os.bundle; import android.text.editable; import android.text.textwatcher; import android.view.view; import android.widget.adapterview; import android.widget.edittext; import android.widget.filterqueryprovider; import android.widget.listview; import android.widget.simplecursoradapter; import android.widget.toast; import android.widget.adapterview.onitemclicklistener; public class androidlistviewcursoradaptoractivity extends activity { private countriesdbadapter dbhelper; private simplecursoradapter dataadapter; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); dbhelper = new countriesdbadapter(this); dbhelper.open(); //clean data dbhelper.deleteallcountries(); //add data dbhelper.insertsomecountries(); //generate listview sqlite database displaylistview();} private void displaylistview() { cursor cursor = dbhelper.fetchallcountries(); //the desired columns bound string[] columns = new string[] { countriesdbadapter.key_code, countriesdbadapter.key_name, countriesdbadapter.key_continent, countriesdbadapter.key_region}; // xml defined views data bound int[] = new int[] { r.id.code, r.id.name, r.id.continent, r.id.region,}; // create adapter using cursor pointing desired data //as layout information dataadapter = new simplecursoradapter( this, r.layout.country_info, cursor, columns, to, 0); listview listview = (listview) findviewbyid(r.id.listview1); // assign adapter listview listview.setadapter(dataadapter); listview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> listview, view view, int position, long id) { // cursor, positioned corresponding row in result set cursor cursor = (cursor) listview.getitematposition(position); //get state's capital row in database. string countrycode = cursor.getstring(cursor.getcolumnindexorthrow("code")); toast.maketext(getapplicationcontext(), countrycode, toast.length_short).show();} }); edittext myfilter = (edittext) findviewbyid(r.id.myfilter); myfilter.addtextchangedlistener(new textwatcher() { public void aftertextchanged(editable s) { } public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before, int count) { dataadapter.getfilter().filter(s.tostring()); } }); dataadapter.setfilterqueryprovider(new filterqueryprovider() { public cursor runquery(charsequence constraint) { return dbhelper.fetchcountriesbyname(constraint.tostring()); } }); } }
country_info.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="6dip" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:text="code: " android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview1" android:layout_below="@+id/textview1" android:text="name: " android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/textview3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview2" android:layout_below="@+id/textview2" android:text="continent: " android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/textview4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview3" android:layout_below="@+id/textview3" android:text="region: " android:textappearance="?android:attr/textappearancemedium" /> <textview android:id="@+id/continent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/textview3" android:layout_alignbottom="@+id/textview3" android:layout_torightof="@+id/textview3" android:text="textview"/> <textview android:id="@+id/region" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/textview4" android:layout_alignbottom="@+id/textview4" android:layout_alignleft="@+id/continent" android:text="textview"/> <textview android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textview3" android:layout_torightof="@+id/textview3" android:text="textview" /> <textview android:id="@+id/code" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textview2" android:layout_alignleft="@+id/name" android:text="textview"/> </relativelayout>
main.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical"> <textview android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="@string/some_text" android:textsize="20sp"/> <edittext android:id="@+id/myfilter" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="@string/some_hint"> <requestfocus /> </edittext> <listview android:id="@+id/listview1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </linearlayout>
manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.as400samplecode" android:versioncode="1" android:versionname="1.0"> <uses-sdk android:minsdkversion="17" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/theme.light"> <activity android:name=".androidlistviewcursoradaptoractivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
things have tried: deleted gen files, cleaned it, went through xml code 4 or 5 times. i've ensured it's imported right. i've checked r file (it has not been generated). error must linked xml cannot find anywhere 1 of can tell me why i'm idiot , i'll grateful.
i not sure can step head.
such
1. delete android.r (in above in activity )
2. or replace package.r example , com.example.name.r
3. check res folder or sub-folder resources .such layout attribute right or not.
4. delete gen , bin folder.
5. clean project thus: project=>clean
6. restart eclipse.
remember if resource not found show type error.
best of luck!
Comments
Post a Comment