1. Are you ready for the Galaxy S20? Here is everything we know so far!

clickable, searchable listview from item-string?

Discussion in 'Android Lounge' started by ElChief, Jan 8, 2020.

  1. ElChief

    ElChief Lurker
    Thread Starter

    Hi everyone!

    can somebody help me making my searchable list clickable? I want to start a new activity through the click.

    I am a total noob and dont understand much... would be greatful for just a piece of code!

    my activity looks like that:


    public class Activity extends AppCompatActivity {

    ListView list;
    ArrayAdapter<String> adapter;

    @override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_1);



    list =(ListView) findViewById(R.id.list);

    ArrayList<String> list1 = new ArrayList<>();
    list1.addAll(Arrays.asList(getResources().getStringArray(R.array.list_1)));


    adapter = new ArrayAdapter<String>(
    Activity.this,
    android.R.layout.simple_list_item_1,
    list1
    );



    list.setAdapter(adapter);





    }


    @override
    public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_menu, menu);
    MenuItem item = menu.findItem(R.id.list_1);
    SearchView searchView = (SearchView) item.getActionView();

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @override
    public boolean onQueryTextSubmit(String s) {
    return false;
    }

    @override
    public boolean onQueryTextChange(String s) {
    adapter.getFilter().filter(s);
    return false;
    }
    });

    return super.onCreateOptionsMenu(menu);



    }
    }
     



    1. Download the Forums for Android™ app!


      Download

       
  2. MoodyBlues

    MoodyBlues Compassion is cool!
    VIP Member

    Welcome to Android Forums, ElChief! :)

    You're most likely to get help by posting on our Android Development board. That's where you can meet and interact with your fellow developers.
     
Loading...

Share This Page

Loading...