Search code examples
androidandroid-listviewclickable

How do you get Eclipse to recognize new Android elements


I am trying to write an android app that has a button that navigates to a Listview. I just add the Listview XML to my project. How do I get my Eclipse project to recognize it so I can use it in my setContentView()

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
    android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawSelectorOnTop="false" />

<TextView 
    android:id="@id/android:empty"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Patient List is Empty"/>

</LinearLayout>

I was attempting to use it in this new ListActivity

public class PatientList extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout);

    List<Map<String, String>> data = new ArrayList<Map<String, String>>();
}
/**
 * 
 */
public PatientList() {
    // TODO Auto-generated constructor stub
}

}

But I can't find it using Eclipse's equivalent intelli-sense. Each element in this listView will be click-able btw probably opening up another List View (that will be retrieved by an http call to an xml file somewhere based on an id in the xml).

I will then attempt to open this on the click of a button that I have... Not the best design, but I will be improving that once I figure out some of the more a way to call xml as an http webservice get the xml and turn it into a listview... This list view is being pre-determined at this point. But any help figuring out how I can now access this listview or make my R.java access it (auto generated, so how do I get that thing to recognize my ListView?) would be greatly appreciated.


Solution

  • First: be careful with the R class. Eclipse offers you to import "android.R". Dont import that. Import your own (sometimes you need to clean the project for eclipse to find it)

    There are some tutorials out there. you should go through one like this one from google: http://developer.android.com/intl/de/resources/tutorials/views/hello-listview.html

    or this one http://www.vogella.de/articles/AndroidListView/article.html