1

I have an EditText in the Header of a ListView along with a Spinner and Button. For some reason, the EditText is not allowing me to type within it. The soft keyboard pops up and a cursor appears in the box onclick, and the keyboard recognizes that I am typing, however nothing appears in the box.

Here's the java for the onCreate that handles making the header.

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.keyvalue);

    m_items = Utils.getTrackerCursor(this, 0, "");

    m_items.getCount();

    startManagingCursor(m_items);

    String[] columns = new String[] {"name","value","result"};
    int[] to = new int[] {R.id.txtkeyValue_rowTitle, R.id.txtkeyValue_rowValue, R.id.txtkeyValue_rowResult};


    m_adapter = new trackerAdapter(this, R.layout.keyvalue_row, m_items, columns, to);




    Button btnRollAll = new Button(this);
    btnRollAll.setText("Roll All");


    final Spinner spinTrackerGroups = new Spinner(m_Context);


    m_trackerGroups = Utils.getTrackerGroups(m_Context);
    String[] spinVals = triMap.getArray(m_trackerGroups); 

    ArrayAdapter<CharSequence> Adap_spinTrackerGroups = new ArrayAdapter<CharSequence>(
            this, android.R.layout.simple_spinner_item, spinVals);

    Adap_spinTrackerGroups.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinTrackerGroups.setAdapter(Adap_spinTrackerGroups);

    EditText search = new EditText(m_Context);
    search.setHint("Search");
    search.setWidth(200);



    LinearLayout lay = new LinearLayout(m_Context);
    lay.addView(spinTrackerGroups);
    lay.addView(search);
    lay.addView(btnRollAll);


    getListView().addHeaderView(lay);


    this.setListAdapter(m_adapter);


    LinearLayout.LayoutParams params = (LayoutParams) spinTrackerGroups.getLayoutParams();
    params.width = 230;
    spinTrackerGroups.setLayoutParams(params);
    spinTrackerGroups.setSelection(1);


}

I'm including the listview's xml as well as the individual listview row's xml for good measure.

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>



    <?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" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="50dp" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >






                <TextView
                    android:id="@+id/txtkeyValue_rowTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_span="3"
                    android:layout_weight=".5"
                    android:ellipsize="middle"
                    android:paddingLeft="10dp"
                    android:text="TextView"
                    android:textSize="16sp"
                    android:singleLine="true" />

   </LinearLayout>
JMD
  • 403
  • 3
  • 6
  • 17
  • Here's something I noticed. Every time I try and type text into it, in the info screen of logcat I get "beginbatchedit: previous batch edit has not ended" and "beginbatchedit() called while in transaction. Ignored." I searched for those errors but the internet does not seem to know what they are. – JMD Jul 06 '12 at 23:45

1 Answers1

1

see this thread please: Focusable EditText inside ListView

Community
  • 1
  • 1
Tomasz Gawel
  • 8,379
  • 4
  • 36
  • 61
  • That post deals with navigating with a trackball/jogger, and he explicitly says that it works when just touching the EditText. None the less I tried it (adding `android:descendantFocusability="beforeDescendants"` to my listview) but no cigar. – JMD Jul 06 '12 at 22:24
  • use rather `afterDescendents` – Tomasz Gawel Jul 06 '12 at 22:27
  • No luck. I also changed my button to bring up a dialog with an edit text to see if it worked there, but no luck on that front either. – JMD Jul 06 '12 at 22:29
  • As a side note, I don't think it's the focusability that is messed up, like I said, it focuses just fine, there is event a cursor that blinks in the box and the keyboard pops up...I just can't type. – JMD Jul 06 '12 at 22:33
  • And if you put for test only textView to header `getListView().addHeaderView(search);` instead of LinearLayout group - still doesnt work? – Tomasz Gawel Jul 07 '12 at 00:01
  • You know what? I went back and did the `android:descendantFocusability="beforeDescendants"` and I mixed it with `putting android:windowSoftInputMode="adjustPan"`, both of which can be found in the article you linked, and it worked. Thank you sir. – JMD Jul 07 '12 at 00:14