@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new MyAdapter(doneNumber1);
listView.setAdapter(adapter);
button.setOnClickListener(this);//点击获取listview里面全部item
}
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void onClick(View v) {
for (int i=0;i<adapter.getCount();i++){
RelativeLayout relativeLayout= (RelativeLayout) listView.getAdapter().getView(i,null,null);//RelativeLayout是listview的item父布局
<span style="white-space:pre"> </span>TextView text= (TextView) relativeLayout.getChildAt(0);//父布局里面的子控件是第几个就填第几个getChildAt
Log.e("asddas",listbutton.getText().toString());
}
break;
}
XML 布局如下
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp">
<TextView
android:id="@+id/tv_gongxudanhao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:paddingTop="10dp"
android:text="单号:"
android:textColor="#f0f"
android:textSize="16dp"
android:textStyle="bold" />
</RelativeLayout>