2016-09-14 7 views
0

これは私のアダプタクラスである: -ビューメソッドがフラグメント内でnullポインタ例外を返すか?

public class PgListAdapter extends RecyclerView.Adapter<PgListAdapter.FaqViewHolder> { 

    private Context mContext; 
    private List<Faq> faqList1; 
    private ValueAnimator mAnimator; 
    private int updatePosition = -1; 
    private int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 
    private int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 
    private Faq ci; 
    private PopupWindow popupWindow; 
    public static View popupView; 
    private Boolean Flag; 


    public PgListAdapter(PgList pgList, Context context, List<Faq> faqList) { 
     mContext = context; 
     this.faqList1 = faqList; 


    } 





    @Override 
    public FaqViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_pglist, parent, false); 
     FaqViewHolder vh = new FaqViewHolder(v); 

     return vh; 


    } 

    @Override 
    public void onBindViewHolder(final FaqViewHolder holder, int position) { 
     ci = faqList1.get(position); 
     holder.questionTv.setText(ci.getQuestion()); 
     holder.answerTextView.setText(ci.getAnswer()); 
     holder.Phone.setText(ci.getPhone()); 
     holder.pgAddress.setText(ci.getAddress()); 


     holder.ll_top.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

      showFilter(); 


      } 
     }); 

     holder.Phone.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent intent = new Intent(Intent.ACTION_DIAL); 
       intent.setData(Uri.parse("tel:" + holder.Phone.getText())); 
       mContext.startActivity(intent); 

      } 
     }); 


     if (ci.isPGFull()) { 
      holder.pgstatus.setVisibility(View.VISIBLE); 
     } else { 
      holder.pgstatus.setVisibility(View.INVISIBLE); 
     } 

    } 


    @Override 
    public int getItemCount() { 
     return faqList1 == null ? 0 : faqList1.size(); 
    } 




    class FaqViewHolder extends RecyclerView.ViewHolder { 
     private RelativeLayout faqItemView; 
     private RelativeLayout extendedView; 
     private TextView questionTv, Phone; 
     private TextView answerTextView, pgstatus, pgAddress; 
     private LinearLayout ll_top; 
     private LinearLayout ll_layout1; 
     private ImageView arrowImgView; 
     private int holderPosition; 

     public FaqViewHolder(View itemView) { 
      super(itemView); 
      Phone = (TextView) itemView.findViewById(R.id.pgPhoneNo1); 
      questionTv = (TextView) itemView.findViewById(R.id.pgOwner); 
      answerTextView = (TextView) itemView.findViewById(R.id.pgPhoneNo); 
      pgstatus = (TextView) itemView.findViewById(R.id.pgstatus); 
      pgAddress = (TextView) itemView.findViewById(R.id.pgAddress); 
      ll_top = (LinearLayout) itemView.findViewById(R.id.ll_top); 
      ll_layout1 = (LinearLayout) itemView.findViewById(R.id.ll_layout1); 




     } 
    } 

これはPopUpWindowを表示する私の方法である: -

public void showFilter() { 


     popupView = LayoutInflater.from(mContext).inflate(R.layout.pglist_popup, null); 

     popupWindow = new PopupWindow(popupView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); 


     final TextView tv_phone = (TextView) popupView.findViewById(R.id.tv_phone); 
     final LinearLayout ll_layout = (LinearLayout) popupView.findViewById(R.id.ll_layout); 
     final LinearLayout ll_top = (LinearLayout) popupView.findViewById(R.id.ll_top); 
     TextView tv_address = (TextView) popupView.findViewById(R.id.tv_address); 
     final TextView btn_ok = (TextView) popupView.findViewById(R.id.btn_ok); 

     // popupWindow.setBackgroundDrawable(new BitmapDrawable()); 
     popupWindow.setOutsideTouchable(false); 
     popupWindow.setFocusable(false); 


     tv_phone.setText(ci.getPhone()); 
     tv_address.setText(ci.getAddress()); 


     tv_phone.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 

       Intent intent = new Intent(Intent.ACTION_DIAL); 
       intent.setData(Uri.parse("tel:" + tv_phone.getText())); 
       mContext.startActivity(intent); 


      } 
     }); 


     btn_ok.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       popupWindow.dismiss(); 
       popupWindow = null; 


      } 
     }); 


     popupWindow.showAsDropDown(popupView, 0, 0); 

    } 

} 

これは私のフラグメントクラスである: -

public class PgList extends Fragment implements WebServiceListener { 


    private String responseCodeCameFromServer = "null"; 
    private String responseCameFromServer, responseMessageCameFromServer; 
    private RecyclerView rvFaqs; 
    private List<Faq> faqList = new ArrayList<>(); 
    private List<NameValuePair> basicNameValuePair; 
    private GeneralUtilities generalUtilities; 
    private SharedPreferencesUtilities sharedPreferencesUtilities; 
    PgListAdapter pgAdapter; 
    private View rootView; 
    private TextView empty_view; 
    ProgressDialog br; 
    private PgList pgList; 


    List<String> typelist = new ArrayList<String>(); 
    List<String> citylist = new ArrayList<String>(); 
    List<CityAreaDetails> temp = new ArrayList<>(); 

    Spinner type; 
    WebServiceHandler webServiceHandler; 


    public PgList() { 

    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 


     if (rootView == null) { 
      rootView = inflater.inflate(R.layout.pglist, container, false); 


      pgList = new PgList(); 
      generalUtilities = new GeneralUtilities(getActivity()); 
      sharedPreferencesUtilities = new SharedPreferencesUtilities(getActivity()); 
      br = new ProgressDialog(getContext()); 
      br.setTitle("Loading..."); 
      br.setCancelable(false); 


      empty_view = (TextView) rootView.findViewById(R.id.tv_empty_view); 

      empty_view.setText("Sorry for the Inconvience! We will update the list very soon for this Area. "); 
      getActivity().setTitle("PG/Room List"); 
      typelist.add("Boys"); 
      typelist.add("Girls"); 
      citylist.clear(); 
      temp.clear(); 


      rvFaqs = (RecyclerView) rootView.findViewById(R.id.overviewRv); 
      rvFaqs.setHasFixedSize(true); 
      rvFaqs.addItemDecoration(new SpacesItemDecoration(20, 20, 12)); 
      rvFaqs.setLayoutManager(new LinearLayoutManager(getActivity())); 

      rvFaqs.setAdapter(new PgListAdapter(getActivity(), faqList)); 
      webServiceHandler = new WebServiceHandler(getActivity()); 
      webServiceHandler.webServiceListener = PgList.this; 
      HashMap<String, String> formData = new HashMap<>(); 
      formData.put("Type", "Boys"); 
      formData.put("CityAreaDetailsID", "1"); 
      if (br != null) { 
       br.show(); 
      } 
      //Checking internet connectivity and then requesting to the server 
      Log.e("", "Data :" + formData); 
      if (generalUtilities.isConnected()) { 
       webServiceHandler.requestToServer((getResources().getString(R.string.api_end_point)) + "CityDetails", 
         WebService.ORDER, formData, true); 
      } else { 
       if (br != null) { 
        br.dismiss(); 
       } 
       generalUtilities.showAlertDialog("Error", getResources().getString(R.string.internet_error), "OK"); 
      } 

     } 


     return rootView; 
    } 

ユーザーリサイクラーの表示アイテムをクリックするとポップアップウィンドウが表示されますが、私の問題はユーザーがリサイクラーの表示アイテムをクリックし、okボタンを押さずにフォンの戻るボタンをクリックすることですポップウィンドウが前のアクティビティに表示されるようにします.iは必要ありません。私はそれをしたいときは、ユーザーが戻るボタンをクリックすると自動的に私は何かのアイデアを教えてくれます。

+0

popupWindow.setOutsideTouchable(false); popupWindow.setFocusable(false); 

を交換してみてください* PgList **? –

+0

@RahulSharma私のコードを見てください。私は、バックボタンをクリックするとアラートダイアログボックスを閉じたいと思う。私はインターフェイスを使用しました。 get viewメソッドはnullポインタの例外を与えます。 – LoveAndroid

+0

ダイアログボックスを閉じるには、ダイアログボックスオブジェクトに対して** dismiss()**を呼び出すだけです。上記のコードと混同しています。 –

答えて

0

はあなた*の内側には何

popupWindow.setOutsideTouchable(true); 
    popupWindow.setFocusable(true); 
+0

それほど多くの先生、その仕事は大丈夫です。 – LoveAndroid

+0

@LoveAndroidようこそ。もう1つ –

+0

あなたが自由であれば。私は私のapp.itsのプッシュ通知を使用してうまく動作します。通知が正しく来ている。しかし、私はタスクマネージャからアプリをきれいにするとき通知は来ていない。あなたが何か考えがあるなら、plaeseを教えてください。これは質問のリンクです: - http://stackoverflow.com/questions/39488909/ongoing-notification-disappears-when-clearing-memory-from-the-device-in-android – LoveAndroid

0

PgListとは何ですか?それは眺めですか? IDで識別する必要があるからです。

編集:アクティビティからonBackPressed()メソッドをオーバーライドしなかった場合、通常、ダイアログは戻るボタンを押すと自動的に閉じます。 とにかく、ダイアログ用に独自のリスナーを実装することができますが、ダイアログのため、全体ではなくビュー:

dialog.setOnKeyListener(new Dialog.OnKeyListener() { 
    @Override 
    public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {   
     if (keyCode == KeyEvent.KEYCODE_BACK) { 
      dialog.dismiss(); 
     } 
     return true; 
    } 
}); 
+0

私のコードを見てください。私はインターフェイスのオーバーライドメソッドでアクションを実行したい。ビューを取得するとnullポインタが返されます。 – LoveAndroid

+0

私は自分の答えを編集しました。見てみましょう。 –

+0

私はこれを試しましたが、実際にはフラグメントを使用していませんでした。リストビューはpresent.andで、リストビューをクリックするとポップアップウィンドウが開きます。 – LoveAndroid

関連する問題