user3395636
user3395636

Reputation: 31

Where I will declare ListView

I am Beginner so please anyone help me where I will declared ListView Layout.
Error is: Your content must have a ListView whose id attribute is 'android.R.id.list.

Below is Main Activity Code:

    public class Check extends ListActivity {
    TextView selection;
    public int idToModify;
    DataManipulator dm;
    List<String[]> list = new ArrayList<String[]>();
    List<String[]> names2 = null;
    String[] stg1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.check);     
        dm = new DataManipulator(this);
        names2 = dm.selectAll();
        stg1 = new String[names2.size()];
        int x=0;
        String stg;

        for(String[] name : names2)
        {
            stg = name[1]+ ","+name[2]+ "," +name[3]+ "," +name[4];
            stg1[x] = stg;
            x++;
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,stg1);
        this.setListAdapter(adapter);
        selection = (TextView)findViewById(R.id.listTextView);
    }

    public void onListItemClick(ListView parent, View v, int position, long id)
    {
        selection.setText(stg1[position]);  
    }
}

Below is ListView Layout Code:

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </ListView>

Upvotes: 0

Views: 112

Answers (2)

Bobbelinio
Bobbelinio

Reputation: 124

Try this:

 android:id="@android:id/list"

Upvotes: 0

Nadir Belhaj
Nadir Belhaj

Reputation: 12063

Your using a built in ListView so your xml file must specify the keyword android while mentioning to a ID.

Rename the id of your ListView like this,

<ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>

Upvotes: 2

Related Questions