是否可以在空的gridview或gridview的空白处处理longclick?我尝试使用如下所示的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridView1);
gridview.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Toast.makeText(MainActivity.this, "does it works?", Toast.LENGTH_SHORT).show();
return false;
}
});
}
但是,不幸的是,它不起作用。有人可以告诉我,我怎样才能在一个空的 gridview 上处理这个事件?谢谢
我还附上了我的 xml 文件:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="-5dip"
android:orientation="vertical" >
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:longClickable="true"
android:layout_weight="1"
android:numColumns="3" >
</GridView>