2016-07-15 12 views
3

ich folgendes Layout haben, activity_main.xml:Wie entfernt man die Ansicht, die injiziert wird?

<merge 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools"> 

    <com.lorentzos.flingswipe.SwipeFlingAdapterView 
    android:id="@+id/frame" 
    android:background="#d1d1d1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:rotation_degrees="15.5" 
    tools:context=".MainActivity" 
    android:layout_gravity="top"/> 

    <TextView 
    android:id="@+id/tv_noJobsLabel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="10dp" 
    android:textStyle="bold" 
    android:textSize="18sp" 
    android:textColor="#474747" 
    android:textAlignment="center" 
    tools:text="Nothing Left to Swipe!" 
    android:layout_gravity="center" /> 

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/fragment_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

    <include layout="@layout/buttons" /> 

</merge> 

In meinem main activity habe ich den folgenden Code für die Injektion mit :

setContentView(R.layout.activity_main); 
ButterKnife.inject(this); 

ich den <include> Teil des Layouts, weil ich zu entferne Ich brauche diese Tasten nicht mehr, aber wenn ich die <include> Zeile entferne bekomme ich den folgenden Fehler:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lorentzos.swipecards.example/com.lorentzos.swipecards.MainActivity}: java.lang.RuntimeException: Unable to inject views for [email protected] 

Was mache ich falsch?
Gibt es einen Grund, warum ich die <include> nicht entfernen kann?


EDIT:

@InjectView(R.id.frame) SwipeFlingAdapterView flingContainer; 

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

    //Remove title bar 
    //this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

    //color the notification bar with our company colors 
    Window window = this.getWindow(); 
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); 
    window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
    window.setStatusBarColor(this.getResources().getColor(R.color.laborswipe_notificationbar)); 

    //remove title from action bar and add the logo to the top left of the action bar 
    setUpActionBar(); 

    setContentView(R.layout.activity_main); 
    ButterKnife.inject(this); 
+2

* ButterKnife.inject (this); * könnte dies ein Tippfehler für 'ButterKnife.bind (this);'? –

+1

Nachdem Sie Ihr '' entfernt haben, entfernen Sie auch die verknüpfte Ansicht aus dem Layout Ihrer Aktivität. –

+0

Ich denke, ich brauche immer noch die Bindung, weil es das Frame-Layout weiter oben in der XML bindet? – user2573690

Antwort

1

Nach dem Entfernen Ihrer <include layout=.../> auch die binded Blick aus dem Layout in Ihrer Tätigkeit entfernen.

Hinweise: Bindungsansichten mit bedeutet, dass Sie Ansichten in einem Layout mit den Bindungscodes in Ihrem main activity haben. Also sollte es einen Code mit folgenden Zeichen geben:

@BindView(R.id.your_view_in_include_button) View yourViewName; 

Entfernen Sie dies entsprechend der Ansicht in Ihrem Include-Layout. Dann erstellen Sie Ihre App neu.

Vorschlag:
auf die aktuelle Version aktualisieren Sie Ihre Buttermesser.