带有编辑框和按钮作为标题的 Android View

标签 android

我有一个以正常方式实现的 ListView 。我想要 ListView 顶部的编辑框和按钮,而不是 ListView 中的每个项目。有人可以为此提供示例代码吗

最佳答案

根据我的理解,您可以尝试这样的操作:

<?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:background="#FF000000" >
    <LinearLayout 
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:id="@+id/linearLayout1"
         android:orientation="horizontal"
        >
     <EditText 
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/et1"
         />
     <Button 
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:id="@+id/bt1"
         android:text="ClickMe"
         />
     </LinearLayout>
     <ListView
        android:id="@+id/list"
        android:layout_below="@id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#000000" />


</RelativeLayout>

不过,您可能需要根据需要自定义一些参数。希望这会有所帮助。

编辑 1:相应的 Java 类

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class AtoZActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ListView lv=(ListView) findViewById(R.id.list);
        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2" };

            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);

            // Assign adapter to ListView
            lv.setAdapter(adapter);
    }
}

在 list 中

  <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".AtoZActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

关于带有编辑框和按钮作为标题的 Android View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9718949/

相关文章:

javascript - 使 View 水平滚动而不是垂直滚动

android - 无法解决错误 BEGIN_ARRAY 但为 BEGIN_OBJECT

java - android 通过 Skype 使用 ACTION_SEND 共享内容(文本+图像),仅共享图像而不共享文本

android - 每当我按操作栏中的按钮时,应用程序崩溃

安卓 : Is there anyway to get battery capacity of a device in mah?

android - 如何在小部件的 TextView 上设置文本

java.lang.InstantiationException : java. lang.Class<com.wavedevelopers.eventsplanning.BookingForm> 没有零参数构造函数

android - NDK/JNI : identifying current thread

android - 如何在 angularjs 中使用 FCMPlugin

android - 应用程序关闭时从 BLE 设备向手机推送通知或 Intent