2016-06-06 31 views
1

Am Erstellen einer Anwendung, wo I ein Fragment aufweisen, wird die XML für das Fragment unterOnTouch nicht auf Listenansicht Arbeits

gegebenen
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/cvCalendar" 
     android:layout_below="@+id/toolbar" 
     android:orientation="vertical"/> 

    <ListView 
     android:id="@+id/lvList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Calendar" 
     android:divider="#cecece" 
     android:dividerHeight="2dp" 
     android:background="#e4c966" /> 

    </RelativeLayout> 

Ich habe eine Linearlayout auf, das einen Kalender anzuzeigen, verwendet wird, und das Ereignisse des Kalenders werden in der folgenden Liste angezeigt. Ich möchte eine Funktion haben, die beim Aufwischen den Kalender verdeckt und beim Wischen nach unten den Kalender anzeigt. Der Java-Code wird unter

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
     { 
     View rootView = inflater.inflate(R.layout.layout, container, false); 
     cala=(LinearLayout)rootView.findViewById(R.id.Calendar); 
     rootView.setOnTouchListener(new View.OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent event) { 
     if(event.getAction() == MotionEvent.ACTION_MOVE){ 

      onTouchEvent(event); 
      } 
     return true; 
      } 
     }); 
      return rootView; 
     } 
public boolean onTouchEvent(MotionEvent touchevent) 
    { 
     switch (touchevent.getAction()) 
     { 
     case MotionEvent.ACTION_DOWN: 
      { 
       x1 = touchevent.getX(); 
       y1 = touchevent.getY(); 
       break; 
       } 
      case MotionEvent.ACTION_UP: 
      { 
       x2 = touchevent.getX(); 
       y2 = touchevent.getY(); 

       if (y1 < y2) 
       { 
        Toast.makeText(getActivity(), "UP to Down Swap Performed", Toast.LENGTH_SHORT).show(); 
        if ((cala.getVisibility())== View.GONE){ 
         cala.setVisibility(View.VISIBLE); } 
        } 

       if (y1 > y2) 
       { 
        Toast.makeText(getActivity(), "Down to UP Swap Performed",Toast.LENGTH_SHORT).show(); 
        if ((cala.getVisibility())== View.VISIBLE){ 
         cala.setVisibility(View.GONE); } 
        } 
       break; 
       } 
      } 
     return false; 
} 
gegeben
+0

Haben Sie die Lösung dieses finden? –

Antwort

0

Das ist für mich gearbeitet: --onCreate()

lvListObject.setOnTouchListener(new View.OnTouchListener() { 
     @Override 
     public boolean onTouch(View view, MotionEvent motionEvent) { 
      onTouchEvent(motionEvent); 
      return false; 
     } 
    });