2016-05-20 10 views
-1

タイトルがAll Postのポップアップウィンドウが表示されています。TextViewをクリックして、リストビューにポップアップウィンドウの2つのアイテムを表示します。リストビューの項目はその項目がTextViewとそれ以前のTextViewに表示されますtitleすべての投稿はclickable item.Butの代わりにlistviewに追加されますが、リストビューは更新時にポップアップウィンドウを閉じることはありません。Androidのポップアップウィンドウでlistviewを更新する方法

ここに私のコードポップアップウィンドウです。このような

 String[] values = new String[] { "All Post", "My Post", "R-Post"}; 
     ArrayList<String> filter_PostType = new ArrayList<String>(); 
     str_LastSelectionValue = sharedPreferences.getString("filter_post_title", ""); 

     if(str_LastSelectionValue.equals("NoVal")) 
     { 
      editor.putString("filter_post_title","All Post"); 
      editor.commit(); 
     } 
     else 
     { 
      str_LastSelectionValue = sharedPreferences.getString("filter_post_title", ""); 
     } 
     textSearch.setText(str_LastSelectionValue); 
     Log.e("", " textSearch.getText().toString().trim() = " + 
     textSearch.getText().toString().trim()); 

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

         popup_searchview = new PopupWindow(CustomActionActivity.this); 
         View layout = getLayoutInflater().inflate(R.layout.allpostsearch_popup, null); 
         popup_searchview.setContentView(layout); 
         popup_searchview.setHeight(220); 
         popup_searchview.setWidth(250); 

         popup_searchview.setOutsideTouchable(true); 
         popup_searchview.setFocusable(true); 
         popup_searchview.setBackgroundDrawable(new BitmapDrawable()); 
         popup_searchview.showAsDropDown(v); 


         filter_list = (ListView) layout.findViewById(R.id.filter_ListView); 
         arr = new ArrayList<String>(Arrays.asList(values)); 
         filter_PostType.clear(); 

         for (int i = 0; i < arr.size(); i++) { 
          String str_PostType = arr.get(i); 

          if (!str_PostType.equals(str_LastSelectionValue)) { 
           filter_PostType.add(str_PostType); 

          } 
         } 

         filterPost_adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.filter_popup_list_item, R.id.text_filter_title, filter_PostType); 
         filter_list.setAdapter(filterPost_adapter); 

         filter_list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
          @Override 
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

           String selectedFromList = (filter_list.getItemAtPosition(position).toString()); 
           editor.putString("filter_post_title", selectedFromList); 
           editor.commit(); 
           textSearch.setText(selectedFromList); 
           popup_searchview.dismiss(); 

           removeItemFromList(position); 
           filterPost_adapter.notifyDataSetChanged(); 

           arr = new ArrayList<String>(Arrays.asList(values)); 
           filter_PostType.clear(); 
           for (int i = 0; i < arr.size(); i++) 
           { 
            String str_PostType = arr.get(i); 

            if (!str_PostType.equals(textSearch.getText().toString().trim())) 
            { 

             filter_PostType.add(str_PostType); 
             int filterSize = filter_PostType.size(); 
             Log.e(" UnMatched ", " In ListItem Click filterSize = " + filterSize); 
            } 
           } 


           filterPost_adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.filter_popup_list_item, R.id.text_filter_title, filter_PostType); 
           filter_list.setAdapter(filterPost_adapter); 

          } 
         }); 
        } 
      }); 
+0

なぜ私の質問は-1マーキングですか? – tazeenmulani

+0

なぜ 'popup_searchview.dismiss();'を呼び出すのですか? –

+0

あなたのアダプターのリファレンスを持っていて、いつでもどこでも変更を通知してください –

答えて

1

使用何か:

String[] values = new String[] { "All Post", "My Post", "R-Post"}; 
     ArrayList<String> filter_PostType = new ArrayList<String>(); 
     str_LastSelectionValue = sharedPreferences.getString("filter_post_title", "NoVal"); 

     if(str_LastSelectionValue.equals("NoVal")) 
      { 
       editor.putString("filter_post_title","All Post"); 
       editor.commit(); 
      } 
      else 
      { 
       str_LastSelectionValue = sharedPreferences.getString("filter_post_title", ""); 
      } 
      textSearch.setText(str_LastSelectionValue); 
      Log.e("", " textSearch.getText().toString().trim() = " + 
      textSearch.getText().toString().trim()); 

     textSearch.setOnClickListener(new View.OnClickListener() { 
        @Override 
        public void onClick(View v) 
        { 
          str_LastSelectionValue = sharedPreferences.getString("filter_post_title", ""); 
          popup_searchview = new PopupWindow(CustomActionActivity.this); 
          View layout = getLayoutInflater().inflate(R.layout.allpostsearch_popup, null); 
          popup_searchview.setContentView(layout); 
          popup_searchview.setHeight(220); 
          popup_searchview.setWidth(250); 

          popup_searchview.setOutsideTouchable(true); 
          popup_searchview.setFocusable(true); 
          popup_searchview.setBackgroundDrawable(new BitmapDrawable()); 
          popup_searchview.showAsDropDown(v); 


          filter_list = (ListView) layout.findViewById(R.id.filter_ListView); 
          if(!filter_PostType.isEmpty()) 
          filter_PostType.clear(); 

          for (int i = 0; i < values.length; i++) { 


           if (!values[i].equals(str_LastSelectionValue)) { 
            filter_PostType.add(values[i]); 

           } 
          } 

          filterPost_adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.filter_popup_list_item, R.id.text_filter_title, filter_PostType); 
          filter_list.setAdapter(filterPost_adapter); 

          filter_list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
           @Override 
           public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

            String selectedFromList = (filter_list.getItemAtPosition(position).toString()); 
            editor.putString("filter_post_title", selectedFromList); 
            editor.commit(); 
            str_LastSelectionValue=selectedFromList; 
            textSearch.setText(selectedFromList); 
            popup_searchview.dismiss(); 

           } 
          }); 
        } 
       }); 


} 

あなたは次回のユーザーがのTextViewをクリックするので、ユーザーが何かを選択した後にアダプターを変更する必要はありませんが、あなたが新しいポップアップウィンドウを作っています新しいアダプター。

理解できないことがあれば、コメントを残してください。

希望します。

+0

コードラインを教えてください。 – tazeenmulani

+0

@tazeenmulani更新を確認してください – Aradhna

+0

しかし、私は3つの文字列{"すべての投稿"、 "私の投稿"、 "R-投稿"}を持っています。 。テキストビューの場合、すべての投稿文字列。リストビュー項目 "My Post"を選択した後、textSearchの "My Post"に "All Post"を置き換え、残りの2文字列には "All Post"と "R-Post"というリストビューが含まれます。その理由は、リストビュー項目のクリックイベントでアダプタを再初期化する理由です。しかし、あなたの提案されたコードワイズリストビューは、2つの文字列 "My Post"と "R-Post"のみを表示することができます。 – tazeenmulani

関連する問題