Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9004807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:59:00+00:00 2026-06-16T00:59:00+00:00

UPDATED ItemEntryFragment.java and ToDoActivity.java to include my latest attempt to get this thing to

  • 0

UPDATED ItemEntryFragment.java and ToDoActivity.java to include my latest attempt to get this thing to work, but it doesn’t

I am in an android development class. our assignment is to make a simple todo list using two fragments. The first fragment is an EditText and the second is a listView.

when a user enters an item into the edittext box and hits enter, the string is added to the listview.

update 2 The application now successfully loads on my phone and the fragments look as expected. however when I press the enter key after inputting text in the EditText line, the setOnKeyListener is never fired. The code segments are the most current.

any suggestions/pointers would be appreciated.

Below are my xml files that I think are correct

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
    android:name="com.todo.ToDoListFragment"
    android:id="@+id/todolistFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<fragment
    android:name="com.todo.ItemEntryFragment"
    android:id="@+id/textboxFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

_

list_view_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > 
<EditText
    android:id="@+id/myEditText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:contentDescription="@string/addItemContentDescription"
    android:hint="@string/addItemHint" />
</LinearLayout>

_

edit_text_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</LinearLayout>

and here are my .java files

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

public class ItemEntryFragment extends Fragment{    

private ToDoListActivity activity;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.text_entry_box, container, false);    
    final EditText myEditText = (EditText)view.findViewById(R.id.myEditText);

    myEditText.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
                if((keyCode == KeyEvent.KEYCODE_DPAD_CENTER) || (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    String newItem = myEditText.getText().toString();
                    activity.addItem(newItem);
                    myEditText.setText("");
                    return true;
                }
            return false;
        }
    });
    return view;
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    this.activity = (ToDoListActivity)activity;
}   
}

_

public class ToDoListFragment extends ListFragment {
//this class is empty because the ListFragment auto adds the ListView
}

and here is my main java file

import java.util.ArrayList;
import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class ToDoListActivity extends Activity {

private ArrayAdapter<String> aa;
private ArrayList<String> todoItems;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //inflate view
    setContentView(R.layout.activity_to_do_list);

    //get references to fragments
    FragmentManager fm = getFragmentManager();

    ToDoListFragment todoListFragment = (ToDoListFragment) fm.findFragmentById(R.id.todolistFragment);

    todoItems = new ArrayList<String>();

    //create array adaptor to bind array to list view
    aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, todoItems);

    //bind array adapter to list view
    todoListFragment.setListAdapter(aa);
}   

public void addItem(String newItem){
    todoItems.add(newItem);
    aa.notifyDataSetChanged();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:59:02+00:00Added an answer on June 16, 2026 at 12:59 am

    Maybe try to hook into onEditorAction and set the EditText properties as mentioned here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED (12/17/2009): Now reflects latest progress I've made. This is the first application that
Updated: This may be an easy or a complex question, but in wpf, I
Updated: This question contains an error which makes the benchmark meaningless. I will attempt
Updated ... i know, my grammar is ambiguous but how can I rewrite this
Updated-2 I have interesting combination of warnings & errors. Firstly, when debugging, i get
UPDATED: I have some table with sync_numbers, like this: --------------------- id | sync_number ---------------------
Updated: please see this other thread instead, all this COM stuff is not part
Updated This is kind of an interesting problem I am experiencing. I need to
UPDATED: This is totally wrong assumption. I retested it and sure enough I was
UPDATED I'm using Devise 1.4.9 for authentication and my Devise-generated User model doesn't seem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.