如何在ListView上禁用onLongClick并从父视图继承onLongClick?

时间:2016-10-22 13:15:20

标签: android listview

我的观点看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:longClickable="true"
    tools:context="com.narudzba.myapplication.MainActivity">
    <ListView
        android:id="@+id/list_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="false"
        android:duplicateParentState="true"
        android:focusableInTouchMode="false" />
</LinearLayout>

我的活动看起来像这样:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.activity_main);
    linearLayout.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Toast.makeText(getApplicationContext(), "HELLO", Toast.LENGTH_LONG).show();
            return true;
        }
    });

    listView = (ListView) findViewById(R.id.list_item);
    listView.setAdapter(new ArrayAdapter<Message>(getApplicationContext(), R.layout.activity_main));

}

我的LinearLayout有onLongPressed()事件,它不会在ListView区域触发,我也不知道为什么?我试图将listview设置为false,将duplicateStateParent设置为true,从ListView中删除焦点...但它不起作用。 在ListView区域上解决onLongPressed事件触发器的任何建议?

0 个答案:

没有答案