1

我在 ListView 的标题中有一个 EditText 以及一个 Spinner 和 Button。出于某种原因,EditText 不允许我在其中输入。弹出软键盘,点击框内出现光标,键盘识别出我正在输入,但框内什么也没有。

这是处理制作标题的 onCreate 的 java。

    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);


}

我将列表视图的 xml 以及单个列表视图行的 xml 包括在内,以便更好地衡量。

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

1 回答 1

1

请看这个线程:Focusable EditText inside ListView

于 2012-07-06T22:01:07.790 回答