EditText上不会显示上面的ListView [英] EditText wont display above ListView

查看:102
本文介绍了EditText上不会显示上面的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListView的活动,我想一个EditText(并最终与它一起一个按钮)来显示它上面。

I have a ListView activity and I want an EditText (and ultimately a button along with it) to display above it.

我相信我的XML是好的,但由于某些原因,EditText上没有显示。 ListView控件占据整个画面:(

I believe my xml is fine, but for some reason the EditText is not displaying. The ListView takes up the entire screen :(

下面就是我的XML看起来像:

Here's what my XML looks like:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <EditText
        android:id="@+id/newitemtext"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:hint="@string/add_new_item"
    android:maxLines="1"
    />
    <ListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />
    <TextView
        android:id="@+id/android:empty"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/inbox_no_items"
    />
</LinearLayout>

任何想法?

请注意:在Eclipse中的XML文件的布局选项卡上,显示的EditText。当我运行我在模拟器应用程序,它没有。

Note: In the layout tab of the xml file in Eclipse, the EditText shows. When I run my application in the emulator, it does not.

感谢您的时间

更新:

下面是我在我的onCreate方法设置内容视图

Here is where I set the content view in my onCreate method

m_aryNewListItems = new ArrayList<MyListItem>();
m_Adapter = new MyListAdapter(this, R.layout.layout_list, m_aryNewListItems);
setListAdapter(m_Adapter);

下面是我的扩展ArrayAdapter:

Here is my extended ArrayAdapter:

private class MyListAdapter extends ArrayAdapter<MyListItem> {

// items in the list
private ArrayList<MyListItem> m_items;

// constructor
public MyListAdapter(Context context, int textViewResourceId, ArrayList<MyListItem> items) {
        super(context, textViewResourceId, items);
        this.m_items = items;
}

// get specific list item
public MyListItem getItem(int position) {
    if (m_items.size() > position) {
        return m_items.get(position);
    }
    else {
        return null;
    }
}

/*
 * Update screen display
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    // get the View for this list item
    View v = convertView;
    if (v == null) {
        LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.layout_list_item, null);
    }

    // get the next MyListItem object
    MyListItem lstItem = m_items.get(position);

    // set up the list item
    if (lstItem != null) {
        TextView txtItem = (TextView) v.findViewById(R.id.list_itemname);
        TextView txtQty = (TextView) v.findViewById(R.id.list_itemqty);
        TextView txtPlace = (TextView) v.findViewById(R.id.list_place);

        // set item text
        if (txtItem != null) {
            txtItem.setText(lstItem.getItemName());
        }

        // set qty text
        String strQtyText = "Qty: ";
        if (txtQty != null && lstItem.getItemQty() != -1) {
            BigDecimal bd = new BigDecimal(lstItem.getItemQty());
            strQtyText += bd.stripTrailingZeros().toString();
            if(lstItem.getItemQtyUnitId() != -1) {
                strQtyText += " " + lstItem.getItemQtyUnitTextAbbrev();
            }
        }
        else {
            strQtyText += "--";
        }
        txtQty.setText(strQtyText);

        // set place text
        if (txtPlace != null && lstItem.getPlaceName() != null) {
            txtPlace.setText(lstItem.getPlaceName());
        }
    }

    // return the created view
    return v;
}

}

推荐答案

添加一个的android:layout_weight =1来的ListView XML

add a android:layout_weight="1" to ListView xml

所以,这件事情:

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

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

        <EditText android:id="@+id/filter"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:inputType="textAutoComplete"
            android:layout_weight="1"
            />

        <Button android:id="@+id/sort"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sort"
            />

        <Button android:id="@+id/add_all"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/add_all"
            />

        <Button android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/add"
            />
    </LinearLayout>

    <GridView android:id="@+id/myGrid"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="1"

        android:verticalSpacing="15dp"
        android:horizontalSpacing="10dp"

        android:numColumns="auto_fit"
        android:columnWidth="60dp"

        android:gravity="center"
        />

</LinearLayout>

此产生:

这篇关于EditText上不会显示上面的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆