【问题标题】:android- I can't hide listview berfore typing in editTextandroid-在输入editText之前我无法隐藏列表视图
【发布时间】:2017-10-03 01:23:51
【问题描述】:

我有一个可以正常工作的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);

        }
    });

【问题讨论】:

    标签: android listview search android-edittext


    【解决方案1】:

    您可以在 onCreate 中隐藏您的 ListView,而不是在 beforeTextChangedonTextChangedafterTextChanged 中,您可以取消隐藏它。

    【讨论】:

      【解决方案2】:

      尝试使用

      listView.setVisibility(View.GONE);
      

      而不是

       listView.setVisibility(View.INVISIBLE);
      

      【讨论】:

        【解决方案3】:

        1.首先hide你的ListView来自lauoutXML或来自onCreate()方法。

        2. 显示来自onTextChanged() 方法的ListView,因为这将在用户键入内容时调用。

        试试这个:

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        
            ...........
            ..................
        
            inputSearch = (EditText) findViewById(R.id.inputSearch);
            listView = (ListView) findViewById(R.id.listView);
        
            // First hide ListView
            listView.setVisibility(View.INVISIBLE);
        
            inputSearch.addTextChangedListener(new TextWatcher() {
        
                @Override
                public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                   // Show ListView
                   if(listView.getVisibility() != View.VISIBLE)
                       listView.setVisibility(View.VISIBLE);
                }
        
                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        
                }
        
                @Override
                public void afterTextChanged(Editable arg0) {
        
                }
            });
        }
        

        【讨论】:

          猜你喜欢
          • 2012-12-30
          • 2017-02-14
          • 2018-09-22
          • 1970-01-01
          • 1970-01-01
          • 2015-03-02
          • 2014-03-29
          • 2020-04-08
          • 1970-01-01
          相关资源
          最近更新 更多