2016-05-05 9 views
0

Ich habe internetnotconnected.xml zu einem linearen Layout aufgeblasen. Ich möchte die Ansicht entfernen, deren Layout aufgeblasen ist, wenn der Benutzer auf die Schaltfläche klickt. Aber mein Weg hat nicht funktioniert.Android - Entfernen von überflutetem Layout xml von einem linearen Layout

if (!EZInternetConnection.isNetworkConnected(context)) { 
      LinearLayout LLPureCard = (LinearLayout) ((Activity) context).findViewById(R.id.ll_main_activity_pure_card); 
      LinearLayout LLPureCardContent = (LinearLayout) ((Activity) context).findViewById(R.id.ll_main_activity_pure_card_content); 
      LLPureCardContent.setVisibility(View.GONE); 
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      inflater.inflate(R.layout.internetnotconnected, LLPureCard); 
      Button button = (Button) ((Activity) context).findViewById(R.id.b_internet_not_connected_try_connection); 
      button.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        if (EZInternetConnection.isNetworkConnected(context)) { 

         LinearLayout LLPureCard = (LinearLayout) ((Activity) context).findViewById(R.id.ll_main_activity_pure_card); 
         LinearLayout LLPureCardContent = (LinearLayout) ((Activity) context).findViewById(R.id.ll_main_activity_pure_card_content); 
         int id = context.getResources().getIdentifier("internetnotconnected", "layout", context.getPackageName()); 
         LLPureCard.removeView(((Activity) context).findViewById(id)); 
         LLPureCardContent.setVisibility(View.VISIBLE); 
         Get20Words(); 
        } 
       } 
      }); 
      this.onCancelled(); 
     } 

Antwort

4

Ich würde versuchen, dies zu tun, ersetzen

inflater.inflate(R.layout.internetnotconnected, LLPureCard); 

mit

zu ersetzen
final View addedView = inflater.inflate(R.layout.internetnotconnected, null); 
LLPureCard.addView(addedView); 

Dann im onClick Verfahren die Linie

LLPureCard.removeView(((Activity) context).findViewById(id)); 

Mit

LLPureCard.removeView(addedView); 
0

Try

int id = context.getResources().getIdentifier("internetnotconnected", "layout", context.getPackageName()); 

von

int id = context.getResources().getIdentifier("internetnotconnected", "id", context.getPackageName()); 
+0

geändert Kenntnis nehmend ersetzen. –

+0

Können Sie eine vollständige Java-Datei posten? Können Sie auch die Internet-Check-Bedingungen entfernen? –

Verwandte Themen