例如,当我按下列表视图上的一个项目的长按,其实际按钮将变为删除按钮。我试着像next_sign.setBackgroundResource(R.drawable.delete);
但是,它强行关闭。
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
//next_sign.setBackgroundResource(R.drawable.delete);
return true;
}
});
12-28 13:44:34.251: E/AndroidRuntime(9108): FATAL EXCEPTION: main 12-28 13:44:34.251: E/AndroidRuntime(9108): java.lang.NullPointerException 12-28 13:44:34.251: E/AndroidRuntime(9108): at com.mycos.cycleborg.PreviousActivity$3.onItemLongClick(MenuListActivity.java:129)
答案 0 :(得分:0)
您必须声明第一个项目的两个按钮并删除布局中相同位置的按钮 使原始按钮可见
android:visibility="visible"
并使用
使删除按钮的可见性在布局中消失android:visibility="gone"
编程中的
lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
Original_Button.setVisibility(View.Gone);
delete_Button.setVisibility(View.Visible);
return true;
}
});
答案 1 :(得分:-1)
public boolean onItemLongClick(AdapterView<?> arg0, View view, int arg2, long arg3) {
Button mButton = (Button)view.findViewById(R.id.button);
mButton.setVisibility(View.Visible);
return true;
}