Tuesday, February 18, 2014

popupwindow added listview, click the item does not disappear when popupwindow problem? ?


I implemented a PopupWindow + listview defined from the drop-down list, but when I click the item after, l list being paid to how the matter,

public void afterTextChanged (Editable e) {
String term = e.toString ();
Log.d ("term", term);
if (e! = null &&! term.equals ("")) {
mohu_findrules = lawDao.mohu_findrules (term);
if (mohu_findrules.size ()> 0) {
termlist = new ListView (
LawMainActivity.this) ;/ / create listview
fuzzyQueryAdapter = new FuzzyQueryAdapter (
LawMainActivity.this,
mohu_findrules) ;/ / this is to load the data adapter
PopUtil.createpop (termlist,
fuzzyQueryAdapter, lm_et, -10) ;/ / call creates popwindow
termlist.setOnItemClickListener (new OnItemClickListener () {
@ Override
public void onItemClick (
AdapterView Parent,
View view, int position, long id) {
String termname = (String) parent
. GetItemAtPosition (position);
lm_et.setText (termname);
PopUtil.closepop () ;/ / corresponding item when popwindow disappear. But not disappear,
}
});
}
}
}



Here is PopUtil class,

public static void createpop (ListView lv, ListAdapter adapter, View v, int n) {
lv.setCacheColorHint (0x00000000) ;/ / buffer color Set Transparent Color
lv.setVerticalScrollBarEnabled (false);
lv.setDivider (null) ;/ / cancel the item dividing line
lv.setAdapter (adapter);

pop = new PopupWindow (lv, v.getWidth (), LayoutParams.WRAP_CONTENT, true);
pop.setBackgroundDrawable (new ColorDrawable (0x33000000));
pop.showAsDropDown (v, 0, n);

}
public static void closepop () {
pop.dismiss ();
}

This whole project is a class I use, all of them can play back, except this one being paid to go, who knows how, gets advice, thank you.

              


<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:

Reply:
Best not to write static, there may be the cause.
Reply:
public static void createpop (ListView lv, ListAdapter adapter, View v, int n) {
lv.setCacheColorHint (0x00000000) ;/ / buffer color Set Transparent Color
lv.setVerticalScrollBarEnabled (false);
lv.setDivider (null) ;/ / cancel the item dividing line
lv.setAdapter (adapter);

pop = new PopupWindow (lv, v.getWidth (), LayoutParams.WRAP_CONTENT, true);
pop.setBackgroundDrawable (new ColorDrawable (0x33000000));
pop.showAsDropDown (v, 0, n);
/ / It should update under

pop.update ();
}
Reply:
Can
lm_et.setText (termname);
lm_et.clearFocus () ;/ / add this to try
PopUtil.closepop ();

No comments:

Post a Comment