EditText旁边的按钮

时间:2014-03-08 07:50:22

标签: android android-listview xamarin android-edittext android-button

在Xamarin中,我有一个带有EditText的布局,我可以输入文本来搜索位置。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:padding="5dip">
    <FrameLayout
        android:id="@+id/mapWithOverlay"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:layout_below="@+id/thumbnail" />
    <ListView
        android:id="@+id/List"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginTop="50dp"
        android:layout_marginBottom="50dp" />
    <EditText
        android:id="@+id/inputSearch"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:hint="Find..."
        android:layout_alignParentTop="true" />
</RelativeLayout>

我需要一个EditText旁边的按钮,我可以点击该按钮清除显示的ListView

如何才能做到这一点?

提前致谢

修改

按钮可以成为控件的一部分吗?

请看一下这个链接:http://components.xamarin.com/

“搜索组件”EditText有一个搜索图标,如果输入了文本,此图标将变为x。

这很容易编码吗?

3 个答案:

答案 0 :(得分:0)

使用此功能。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="5dip" >

<FrameLayout
    android:id="@+id/mapWithOverlay"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/thumbnail"
    android:background="#ffffff" />

<ListView
    android:id="@+id/List"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="50dp"
    android:layout_marginTop="50dp" />

<EditText
    android:id="@+id/inputSearch"
    android:layout_width="235dp"
    android:layout_height="50dp"
    android:layout_alignParentTop="true"
    android:hint="Find..." />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/inputSearch"
    android:layout_alignRight="@+id/mapWithOverlay"
    android:text="Button" />

</RelativeLayout>

或另一个

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="5dip" >

<FrameLayout
    android:id="@+id/mapWithOverlay"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/thumbnail"
    android:background="#ffffff" />

<ListView
    android:id="@+id/List"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="50dp"
    android:layout_marginTop="50dp" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/inputSearch"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight=".7"
        android:hint="Find..." />

    <Button
        android:id="@+id/button1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".3"
        android:text="Button" />
</LinearLayout>

</RelativeLayout>

答案 1 :(得分:0)

尝试如下......

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:orientation="vertical"
    android:padding="5dip" >

    <FrameLayout
        android:id="@+id/mapWithOverlay"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/thumbnail"
        android:background="#ffffff" />

    <ListView
        android:id="@+id/List"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginBottom="50dp"
        android:layout_marginTop="50dp" />

    <LinearLayout
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentTop="true"
       android:orientation="horizontal" >

        <EditText
            android:id="@+id/inputSearch"
            android:layout_width="0dip"
            android:layout_height="50dp"
            android:layout_weight="1"
            android:hint="Find..." />

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

    </LinearLayout>

</RelativeLayout>

答案 2 :(得分:0)

你想要这个

<FrameLayout
    android:id="@+id/mapWithOverlay"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff" >

    <EditText
        android:id="@+id/inputSearch"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:ems="10"
        android:hint="Find..."
        android:paddingRight="30dp"
        android:singleLine="true" >

        <requestFocus />
    </EditText>

    <ImageView
        android:id="@+id/btn_clear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:src="@android:drawable/ic_notification_clear_all" />
</FrameLayout>

<ListView
    android:id="@+id/List"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/mapWithOverlay" >
</ListView>

使用图像清除

btn_clear=(ImageView)findViewById(R.id.btn_clear);
btn_clear.setOnClickListner(new OnClickListner){
   //do clear your edittext
)};