2012-03-15 42 views
1

我有一個listview,我已經以正常的方式實現。我想要列表視圖頂部的編輯框和按鈕,而不是列表視圖中的每個項目。可能有人向我提供的示例代碼用於此目的Android視圖編輯框和按鈕作爲標題

+1

烏拉圭回合目前的工作提供了SRC,然後我們可以幫助更好。 – Deva 2012-03-15 11:43:15

+0

已添加活動/佈局/清單條目,看看是否有幫助。 – Deva 2012-03-15 11:58:46

回答

1

根據我可以解釋你可以嘗試類似這個:

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

而且在清單

<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> 
+0

感謝您的幫助 – user1092042 2012-03-15 12:08:05

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

    <LinearLayout 
     android:id="@+id/listado_ly_search" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" 
     android:orientation="horizontal" > 

     <EditText 
      android:id="@+id/listado_tb_filtro" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.45" android:layout_gravity="center_vertical"> 

     </EditText> 

     <Button 
      android:id="@+id/listado_iv_search" 
      android:layout_width="48dp" 
      android:layout_height="48dp" android:background="@android:drawable/ic_menu_search"/> 


    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/LinearLayout01" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:minHeight="200sp" 
     android:orientation="horizontal" > 


      <ListView 
       android:id="@+id/android:list" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" 
       android:choiceMode="singleChoice" 
       android:drawSelectorOnTop="false" 
       android:minHeight="200sp" > 
      </ListView> 
    </LinearLayout> 
1

嘗試用這個..

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

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <EditText 
      android:id="@+id/edtxt" 
      android:layout_width="100dp" 
      android:layout_height="50dp" 
      android:inputType="none" /> 

     <Button 
      android:id="@+id/btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="2dp" 
      android:layout_marginRight="3dp" 
      android:layout_marginTop="2dp" 
      android:text="button" 
      android:textSize="15sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <ListView 
      android:id="@+id/list" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" > 
     </ListView> 
    </LinearLayout> 

</LinearLayout> 

java文件看起來像這樣

public class example extends Activity { 
private ListView listView; 
static String[] names; 
@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     listView = (ListView) findViewById(R.id.phlist); 
Button btn = (Button) findViewById(R.id.btn); 
EditText ed = (EditText)findViewById(R.id.edtxt); 
names = new String[] { "name1", "name2", "name3", "name4" }; 
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, android.R.id.text1, values); 

      lv.setAdapter(adapter); 

btn.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
//write Ur Code for Button Clik 

} 
}); 

} 
} 

請參閱本link.it可能有用.. enter link description here

+0

你可以請張貼的Java代碼,以膨脹edittext和按鈕作爲標題,並填充列表視圖 – user1092042 2012-03-15 11:54:47