【发布时间】:2016-12-16 11:58:24
【问题描述】:
我在列表视图中使用按钮... 我的xml代码...
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="false"
android:layout_alignParentEnd="false">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/patient_info"
android:id="@+id/textView"
android:layout_alignParentTop="false"
android:textSize="30sp"
android:layout_alignParentLeft="false"
android:layout_alignParentStart="false"
android:layout_toLeftOf="@+id/button3"
android:layout_toStartOf="@+id/button3"
android:layout_marginRight="5dp"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="right">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add"
android:id="@+id/button1"
android:layout_alignParentRight="false"
android:layout_alignParentEnd="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sync"
android:id="@+id/button3"
android:layout_alignParentTop="false"
android:layout_toLeftOf="@+id/button1"
android:layout_toStartOf="@+id/button1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ProgressBar
style="@android:style/Widget.Material.Light.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar2" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editText11"
android:hint="Old Registration Number" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editText10"
android:hint="New Registartion Number" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editText7"
android:hint="Name" />
<Button
android:text="search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="SEARCH RESULTS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:textSize="20sp"
android:gravity="center"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</LinearLayout>
</LinearLayout>
如何处理列表视图中的每个按钮单击。? 活动类
String[] from = new String[]{DBHelper.ID, DBHelper.FNAME, DBHelper.LNAME, DBHelper.ADDRESS, DBHelper.REGID};
int[] to = new int[]{R.id.id,R.id.fname,R.id.lname,R.id.address,R.id.regid};
adapter = new SimpleCursorAdapter(this, R.layout.list, cursor, from, to, 0);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//listview click event handling
id = (TextView) arg1.findViewById(R.id.id);
int id_To_Search = Integer.valueOf(id.getText().toString());
Bundle dataBundle = new Bundle();
dataBundle.putInt("_id", id_To_Search);
Intent intent = new Intent(getApplicationContext(), AddPatient.class);
intent.putExtras(dataBundle);
startActivity(intent);
}
});
如何管理列表视图中每个项目的按钮单击。我尝试了很多方法。我该如何解决这个问题。?请任何人帮助我...
【问题讨论】:
-
对每个按钮使用
android:onClick属性。