pramod.deore
Newbie
Hello everybody,
I am trying to run my first program in android but I got error.
I havae following code in my .java file
package com.micro;
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 ToDoList1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
setContentView(R.layout.main); //error
ListView myListView = (ListView)findViewById(R.id.myListView); //error
final EditText myEditText = (EditText)findViewById(R.id.myEditText); //error
final ArrayList<String> todoItems = new ArrayList<String>();
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,todoItems);
myListView.setAdapter(aa);
myEditText.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(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;
}
});
}
}
and following in my main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New To Do Item"
/>
<ListView
android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
But when I tried to run the program I got 3 error as "R can not be resolved" at shown above.
I had to find out solution for this but my problem is not solved. Some forum says make another program and run it. I tried it for 3 times but every time I got same error as "R can not be resolved". Please help me.
Thank you
I am trying to run my first program in android but I got error.
I havae following code in my .java file
package com.micro;
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 ToDoList1 extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle)
{
setContentView(R.layout.main); //error
ListView myListView = (ListView)findViewById(R.id.myListView); //error
final EditText myEditText = (EditText)findViewById(R.id.myEditText); //error
final ArrayList<String> todoItems = new ArrayList<String>();
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,todoItems);
myListView.setAdapter(aa);
myEditText.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(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;
}
});
}
}
and following in my main.xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
androidrientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="New To Do Item"
/>
<ListView
android:id="@+id/myListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
But when I tried to run the program I got 3 error as "R can not be resolved" at shown above.
I had to find out solution for this but my problem is not solved. Some forum says make another program and run it. I tried it for 3 times but every time I got same error as "R can not be resolved". Please help me.
Thank you