开发者

Android: Launching new activity from dialog

I'm trying to use a custom dialog to get user input for a title String, and then if the user clicks OK, it will fire up a new Activity (basically a notepad) with that title String as the title. However, when I try to call the method that fires the new activity inside onClick(), it gives me an error.

Here's the code

class NewListDialog extends Dialog implements OnClickListener {

        Button search;
        EditText text;

        public NewListDialog(Context context) {
            super(context);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.newlist_dialog);
            search = (Button) findViewById(R.id.dialog_confirm);
            text = (EditText) findViewById(R.id.dialog_editable);
            search.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (v == search) {
                String title_name = text.getText().toString();

                       // method for launching new activity
               fireListEdit(title_name);  
            }
        }

}

void fireListEdit(String title_name) {
        Intent i = new Intent(this, ListEdit.class);
        开发者_运维技巧i.putExtra(InvenDB.KEY_TITLE, title_name);
        startActivityForResult(i, ACTIVITY_CREATE);
}

And I call this dialog with

@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
    switch(item.getItemId()) {
    case INSERT_ID:
        NewListDialog dialog = new NewListDialog(this);
        dialog.show();
        return true;
    case QUIT_ID:
        finish();
        return true;
    }
    return super.onMenuItemSelected(featureId, item);
}

Edit: when I run it on emulator, when I click OK on the custom dialog it just gives me "the application stopped unexpectly" error

EDIT:

This is the logcat, I'm not really sure what they mean :\

01-12 17:39:27.668: ERROR/AndroidRuntime(426): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jin.inventoryapp/com.jin.inventoryapp.ListEdit}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0


From what I can tell there is a problem with the Adapter (data) part of your application. Whatever Adapter class you used to back your com.jin.inventoryapp.ListEdit, it has a problem accessing the data. i.e. if you are using an array or database to populate your ListView, check there first.

This is useful to figure out who is throwing an exception.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜