2016-05-05 2 views
0

Я раздул internetnotconnected.xml на линейный макет. Я хочу удалить View, который раздувается, когда пользователь нажимает кнопку. Но мой путь не сработал.Android - Удаление завышенного макета xml из линейного макета

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(); 
     } 

ответ

4

Я хотел бы попробовать сделать это, замените

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

с

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

Затем в методе OnClick заменить строку

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

С

LLPureCard.removeView(addedView); 
0

Попробуйте заменить

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

по

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

Отметив изменилось. –

+0

Можете ли вы разместить полный java-файл? Можете ли вы также удалить условия проверки интернета? –

Смежные вопросы