need help


Last Updated:

  1. pisitpong

    pisitpong New Member This Topic's Starter

    Joined:
    Oct 21, 2010
    Messages:
    2
    Likes Received:
    0
    i copy this code from textbook. there is no error but when i run this on the emulator 1.6 i t crash.
    Code (Text):
    1. package com.helloworld2;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import android.app.Activity;
    6. import android.os.Bundle;
    7. import android.view.KeyEvent;
    8. import android.view.View;
    9. import android.view.View.OnKeyListener;
    10. import android.widget.ArrayAdapter;
    11. import android.widget.EditText;
    12. import android.widget.ListView;
    13.  
    14. public class HelloWorld extends Activity {
    15.     /** Called when the activity is first created. */
    16.     @Override
    17.     public void onCreate(Bundle savedInstanceState) {
    18.         setContentView(R.layout.main);
    19.      // Get references to UI widgets
    20.      ListView myListView = (ListView)findViewById(R.id.myTextView);
    21.      final EditText myEditText = (EditText)findViewById(R.id.myEditText);
    22.   // Create the array list of to do items
    23.      final ArrayList<String> todoItems = new ArrayList<String>();
    24.      // Create the array adapter to bind the array to the listview
    25.      final ArrayAdapter<String> aa;
    26.      aa = new ArrayAdapter<String>(this,
    27.      android.R.layout.simple_list_item_1,
    28.      todoItems);
    29.      // Bind the array adapter to the listview.
    30.      myListView.setAdapter(aa);
    31.      myEditText.setOnKeyListener(new OnKeyListener() {
    32.          public boolean onKey(View v, int keyCode, KeyEvent event) {
    33.          if (event.getAction() == KeyEvent.ACTION_DOWN)
    34.          if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
    35.          {
    36.          todoItems.add(0, myEditText.getText().toString());
    37.          aa.notifyDataSetChanged();
    38.          myEditText.setText("");
    39.          return true;
    40.          }
    41.          return false;
    42.          }
    43.          });
    44.     }
    45. }
     

    Advertisement
  2. pisitpong

    pisitpong New Member This Topic's Starter

    Joined:
    Oct 21, 2010
    Messages:
    2
    Likes Received:
    0
    more info it is ToDolist app
     
  3. copestag

    copestag Well-Known Member

    Joined:
    May 23, 2010
    Messages:
    1,355
    Likes Received:
    247
    Welcome to the forums :)

    Ive moved this thread to the developers forum for you so it can be better seen by members who are familiar with app development
     
  4. sscAndroid

    sscAndroid Member

    Joined:
    Oct 23, 2010
    Messages:
    17
    Likes Received:
    1
    "It crashes" is not a very meaningfull error description ;)

    Could you check the logcat output and tell us which kind of error you get ?
     

Share This Page

Loading...