Cannot resolve method 'getStringArrayList' when I'm making a search filter for Listview

前端 未结 1 421
余生分开走
余生分开走 2021-01-25 23:26

I\'m a beginner, I\'m creating a job search app which shows job infomation as listview where the data is from WAMP server database. I encounter a problem : Cannot resolve method

1条回答
  •  孤街浪徒
    2021-01-25 23:35

    getStringArrayList is a method on Bundle (such as savedInstanceState). There's no such method in Activity. Hope that helps.

    Currently your infoList is an ArrayList>, something that is harder to pass directly to an activity. So find a way to represent it as an ArrayList, or find a more suitable datatype supported by Intent's putExtra-methods. Here below is a suggested solution using an ArrayList.

    Passing the data into the activity with the Intent allows you to get it back in your SearchFilter. In the calling activity put something like this:

    Intent i = new Intent(this, SearchFilter.class);
    i.putStringArrayListExtra("com.yourpackagename.here.keynamehere", aStringArrayList);
    

    In SearchFilter.java, put something like this:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        filterText = (EditText) findViewById(R.id.search_box);
        filterText.addTextChangedListener(filterTextWatcher);
    
        Intent startingIntent = getIntent();
    
        ArrayList arrayList = new ArrayList();
        if (startingIntent != null) {
           arrayList = startingIntent.getStringArrayList("com.yourpackagename.here.keynamehere");
        }
        setListAdapter(new ArrayAdapter(this,
            android.R.layout.simple_list_item_1,
            arrayList));
    }      
    

    0 讨论(0)
提交回复
热议问题