我正在尝试在我expandable ListView
的群组文字视图右侧添加删除按钮。
出现按钮但列表不再展开。这是我用来添加按钮的代码。
我的list_group.xml
的一部分,我的列表中包含父文字视图。
<TextView
android:id="@+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="17dp"
android:textColor="#FD0987" />
<Button
android:id="@+id/delButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/button_gplus_gb"
android:text ="@string/Delete"
/>
</RelativeLayout>
附加了将按钮添加到xml之前和之后的图像。在第一个列表中,列表在添加按钮之后在第二个列表中展开,而不是。
答案 0 :(得分:2)
检查此问题并回答:button in expandable listview android。
根据这个,按钮应该是不可聚焦的。
答案 1 :(得分:1)
您仍然需要让用户确认删除。因此,直接使用警报对话框,
Button btn = (Button) findViewById(R.id.btn1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(
MyApp.this);
builder.setTitle("Delete?");
builder.setMessage("Are you sure?");
builder.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
});
builder.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
//do something to delete file.
}
. });
builder.show();
}
});