0

This is an Android Project. I was trying this tutorial: http://www.edumobile.org/android/android-programming-tutorials/search-interface/

I did all the steps but i have an error in R.xml.words. xml underlined anyone know how to fix this?

package com.app.SearchInterfaceDemo;

import android.os.Bundle;
import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import com.app.SearchInterfaceDemo.R;

abstract public class SearchInterfaceBase extends ListActivity {
abstract ListAdapter makeMeAnAdapter(Intent intent);

private static final int LOCAL_SEARCH_ID = Menu.FIRST+1;
private static final int GLOBAL_SEARCH_ID = Menu.FIRST+2;
TextView selection;
ArrayList<String> items=new ArrayList<String>();

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    selection=(TextView)findViewById(R.id.selection);

    try {
        XmlPullParser xpp=getResources().getXml(R.xml.words);

        while (xpp.getEventType()!=XmlPullParser.END_DOCUMENT) {
            if (xpp.getEventType()==XmlPullParser.START_TAG) {
                if (xpp.getName().equals("word")) {
                    items.add(xpp.getAttributeValue(0));
                }
            }
                xpp.next();
        }
    }
    catch (Throwable t) {
        Toast
            .makeText(this, "Request failed: "+t.toString(), 4000)
            .show();
    }

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    onNewIntent(getIntent());
}

@Override
public void onNewIntent(Intent intent) {
    ListAdapter adapter=makeMeAnAdapter(intent); 
    if (adapter==null) {
        finish();
    }
    else {
        setListAdapter(adapter);
    }
}

public void onListItemClick(ListView parent, View v, int position,long id) {
    selection.setText(parent.getAdapter().getItem(position).toString());
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(Menu.NONE, LOCAL_SEARCH_ID, Menu.NONE, "Local Search").setIcon(android.R.drawable.ic_search_category_default);
    menu.add(Menu.NONE, GLOBAL_SEARCH_ID, Menu.NONE, "Global Search").setIcon(R.drawable.search).setAlphabeticShortcut(SearchManager.MENU_KEY);

    return(super.onCreateOptionsMenu(menu));
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case LOCAL_SEARCH_ID:
            onSearchRequested(); 
            return(true);

        case GLOBAL_SEARCH_ID:
            startSearch(null, false, null, true); 
            return(true);
    }
    return(super.onOptionsItemSelected(item));
}
}
Hanzo Kimura
  • 91
  • 1
  • 1
  • 6

1 Answers1

1

Try to use XmlResourceParser instead of XmlPullParser in this line : XmlPullParser xpp=getResources().getXml(R.xml.word);

koni
  • 1,805
  • 1
  • 14
  • 13
  • even i imported android.content.res.XmlResourceParser; – Hanzo Kimura Jan 14 '14 at 21:13
  • Are you sure you named you file word.xml ? You want to open word.xml and not words.xml like you asked maybe a prob here... – koni Jan 14 '14 at 21:33
  • changed it to xml.words but still i get the error... the underlined one is the xml not the words though :( – Hanzo Kimura Jan 14 '14 at 21:36
  • Try to clean your project or restart your IDE maybe, i tried this code and it works fine – koni Jan 14 '14 at 21:38
  • Still the same. underlined xml in R.xml.words and a new error: in manifest – Hanzo Kimura Jan 14 '14 at 21:59
  • You don't have the picture "browser" in res/drawable, just remplace it by @drawable/ic_launcher (but verify if it's in drawable/hdpi) And for your problem, you don't have any informations about this underline ? No hint ? – koni Jan 14 '14 at 22:32
  • the browser is fixed now. but the underlined xml is still not fixed. when i hover to it, it says "xml cannot be resolved or is not in the field" and when i hit f3 on R it brings me to R.java i tried right click and making solutions but it just gives me a code under R.java to make an object named xml – Hanzo Kimura Jan 14 '14 at 23:01
  • maybe from you import: `import com.app.SearchInterfaceDemo.R;` try to delete this import to see.... – koni Jan 15 '14 at 11:24