2014-11-11 2 views
1

그래서 프로그램이 정상적으로 작동합니다. 나는 세 가지 경고 만 남았고 (각 팝업 창에 하나씩), 나는 나를 많이 귀찮게한다. 나는 나의 필요에 맞는 해결책을 찾고있다. 그러나 나는 그것을 찾을 수 없다. popupwindow를 사용하여 "null을 뷰 루트로 전달하지 않음"

은 내 코드 (다른 두 popupwindows이 유사)

else if(id == R.id.action_resetstats){ 
     LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
     View popupView = layoutInflater.inflate(R.layout.resetpop, null); 
     final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

     Button yesDismiss = (Button)popupView.findViewById(R.id.yesDismiss); 
     yesDismiss.setOnClickListener(new Button.OnClickListener(){ 
      @Override 
      public void onClick(View v){ 
       SharedPreferences prefs = getSharedPreferences(savedData, Context.MODE_PRIVATE); 
       Editor editor = prefs.edit(); 
       editor.clear(); 
       editor.commit(); 

       counterW = 0; 
       counterL = 0; 
       counterT = 0; 
       counterTot = 0; 
       timerTime = 3; 

       popupWindow.dismiss(); 
      } 
     });  

     popupWindow.showAsDropDown(yeDismiss, 50, 50); 


     Button noDismiss = (Button)popupView.findViewById(R.id.noDismiss); 
     noDismiss.setOnClickListener(new Button.OnClickListener(){ 
      @Override 
      public void onClick(View v){ 
       popupWindow.dismiss(); 
      } 
     });  

     popupWindow.showAsDropDown(naDismiss, 50, 50); 

XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_centerHorizontal="true" 
android:layout_centerVertical="true" 
android:layout_margin="5dp" 
android:background="@android:color/black" 
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<RelativeLayout 
    android:layout_width="230dp" 
    android:layout_height="300dp" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:layout_margin="2dp" 
    android:background="@android:color/darker_gray" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/noDismiss" 
     android:layout_width="100dp" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="NO!" /> 

    <RelativeLayout 
     android:id="@+id/relativeLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_margin="20dp" 
     android:orientation="vertical" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="  Reset stats?" 
      android:textSize="22sp" /> 
    </RelativeLayout> 

    <Button 
     android:id="@+id/yesDismiss" 
     android:layout_width="100dp" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:text="Yes" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/relativeLayout1" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="34dp" 
     android:text="Are you sure you want " /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView1" 
     android:layout_centerHorizontal="true" 
     android:text="to reset your statistics?" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView2" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="39dp" 
     android:text="!CANNOT BE UNDONE!" /> 

</RelativeLayout> 

</RelativeLayout> 

문제는 물건을 정리하기 위해 여기에 있습니다 :

View popupView = layoutInflater.inflate(R.layout.resetpop, null); 

및 경고 sais :

Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's root element) 

모든 아이디어를 어떻게 해결할 수 있을까요? 미리 감사드립니다!

+0

무엇이 문제입니까? – Blackbelt

+0

경고를 잊어 버렸습니다. 지금 편집해야합니다. – Gerfort

+0

나는 본다. 레이아웃 제약 조건을 복사하려면 일반적으로 상위 레이아웃을 제공해야합니다. 당신의 경우에는, 당신이 경고를 무시할 수 간단하다고 생각합니다 – Blackbelt

답변

5

당신은 사용할 수 있습니다

context = popupView.getContext(); 
inflater.inflate(R.layout.resetpop, new LinearLayout(context), false); 

경고를 해결해야한다고. 당신이 코드를 블로그 아래에 쓸 때

0

, 당신은, 부모와 레이아웃을 팽창 부모에 첨부 의미하지만 때문에 패스 널의, 인플레이터 늘 새로운 부모를 첨부 할 수

View popupView = layoutInflater.inflate(R.layout.resetpop, null); 

LayoutInflater class -->

350 
    351 public View More ...inflate(int resource, ViewGroup root) { 
    352  return inflate(resource, root, root != null); 
    353 } 

그러나 이것은 주어진 부모와 함께 팽창 할 것이지만 새로운 부모에게는 붙이지 않을 것입니다.

View popupView = layoutInflater.inflate(R.layout.resetpop, new LinearLayout(context), false); 
+0

그는 필요가 없습니다. 그가 말했듯이, 그의 코드는 잘 작동하고 있었고, 그는 단지 경고를 없애고 싶었습니다. inflate 메소드의 false는 실제적으로 NULL을 전달하는 것과 동일하지만 (코드 스 니펫으로 설명하는 것처럼) 경고를 발생시키지 않습니다. – SubliemeSiem

+0

그것은 단지 더 많은 정보입니다 :) 나는 당신의 대답이 사실임을 압니다. – Talha

+0

나는 배우기를 좋아합니다. – Gerfort