如何在列表视图中添加按钮?

时间:2011-07-04 04:25:30

标签: android listview

我正在尝试在listview中添加按钮。怎么做?

我的代码和xml文件如下:

public class Second extends ListActivity {
Button btn;
ListView lst;
    @Override
    protected void onCreate(Bundle abc) {
        // TODO Auto-generated method stub
        super.onCreate(abc);
        setContentView(R.layout.nit);
        lst=getListView();
        lst.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1,WORLDCUP2010));


        btn=(Button)findViewById(R.id.button1);
        btn.setOnClickListener(new View.OnClickListener() {


             public void onClick(View v) {
                Intent i=new Intent(Second.this,Fifth.class);
                startActivity(i);

             }});

    }
    static final String[] WORLDCUP2010 = new String[] {
        "Citrzen",  "Disprine", "Gelosil", 
        "", "", "", 
        "", "", "", 
         };
}

和xml如下,

LinearLayout android:id="@+id/linearLayout1" xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"
LinearLayout 
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:padding="3dp"
    Button android:background="@drawable/med"
        android:layout_gravity="center" android:id="@+id/button1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
/Button
    ListView android:layout_height="wrap_content" android:id="@+android:id/listView1"
        android:layout_width="fill_parent" android:layout_weight="1"
/ListView

/LinearLayout
/LinearLayout

0 个答案:

没有答案