我有一個editText和一個正常工作的列表視圖。但是我想讓listview在用戶開始輸入之前不可見。 我看着這些鏈接,但它沒有工作android-我不能隱藏listview berfore在editText中輸入
Show/Hide the Custom ListView in android
Hiding Listview until search is initiated
Hide an android ListView until search string is entered
這裏是我的代碼
public class MapAcWithMarker extends FragmentActivity implements OnMapReadyCallback {
public ListView listView;
private View parentView;
public DataAdapter adapter;
ArrayList<Locations> arrayListTemp=new ArrayList<>();
EditText inputSearch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_recyc);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
inputSearch = (EditText) findViewById(R.id.inputSearch);
listView = (ListView) findViewById(R.id.listView);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
if(listView.getVisibility() != View.INVISIBLE)
listView.setVisibility(View.INVISIBLE);
}
@Override
public void afterTextChanged(Editable arg0) {
if(listView.getVisibility() != listView.VISIBLE)
listView.setVisibility(listView.VISIBLE);
}
});
由於它的工作! –