hi, just verify how is the id to the listview defined in the layout file. if it is as android:list in the layout,then u need to specify it as (android.R.id.list) in the findViewById method
On Mar 28, 9:52 pm, mnavlani <monishanavl...@gmail.com> wrote: > hello all, > this is my first attempt at the UI. i tried to create a list view > using the following code: > > package com.paad.todolist2; > > import java.util.ArrayList; > > import android.app.Activity; > import android.os.Bundle; > import android.view.KeyEvent; > import android.view.View; > import android.view.View.OnKeyListener; > import android.widget.ArrayAdapter; > import android.widget.EditText; > import android.widget.ListView; > > public class ToDoList2 extends Activity { > /** Called when the activity is first created. */ > // @Override > // public void onCreate(Bundle savedInstanceState) { > // super.onCreate(savedInstanceState); > // setContentView(R.layout.main); > // } > public void onCreate(Bundle savedInstanceState) { > // Inflate your view > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > // Get references to UI widgets > ListView myListView = (ListView)findViewById(R.id.myListView); > final EditText myEditText = > (EditText)findViewById(R.id.myEditText); > // Create the array list of to do items > final ArrayList<String> todoItems = new ArrayList<String>(); > // Create the array adapter to bind the array to the listview > final ArrayAdapter<String> aa; > aa = new > ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,todoItems); > // Bind the array adapter to the listview. > myListView.setAdapter(aa); > myEditText.setOnKeyListener(new OnKeyListener() { > public boolean onKey1(View v, int keyCode, KeyEvent event) { > if (event.getAction() == KeyEvent.ACTION_DOWN) > if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) > { > todoItems.add(0, myEditText.getText().toString()); > aa.notifyDataSetChanged(); > myEditText.setText(" "); > return true; > } > return false; > } > > @Override > public boolean onKey(View arg0, int arg1, KeyEvent > arg2) { > // TODO Auto-generated method stub > return false; > } > }); > } > > } > > but, the line: > ListView myListView = (ListView)findViewById(R.id.myListView); > is giving an error :"R.id cannot be resolved". > > please help me regarding this. > > regards -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.