How to add button in List View?
I am trying to add button in listview. How to do this?
My code and xml file are as follows:
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",
"", "", "",
"", "", "",
};
}
and the xml is as follows,
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/m开发者_JAVA百科ed"
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
精彩评论