Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:44:32+00:00 2026-06-17T19:44:32+00:00

I came across a nice filterable listview tutorial and I was wondering how to

  • 0

I came across a nice filterable listview tutorial and I was wondering how to determine what listview item is selected and display a toast. Here is the code:

package com.example.listview;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ListView;
import android.widget.TextView;


public class TestFilterListView extends Activity {
FrameLayout historyContainer;
ViewStub viewStub;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.history_container);
    historyContainer = (FrameLayout) findViewById(R.id.historyContainerLayout);
    EditText filterEditText = (EditText) findViewById(R.id.filter_text);
    filterEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            historyContainer.removeAllViews();
            final List<String> tempHistoryList = new ArrayList<String>();
            tempHistoryList.addAll(historyList);
            for(String data : historyList) {
                if(data.indexOf((s.toString())) == -1) {
                    tempHistoryList.remove(data);
                }
            }
            viewStub = new ViewStub(TestFilterListView.this, R.layout.history_schedule);
            viewStub.setOnInflateListener(new ViewStub.OnInflateListener()
            {
                public void onInflate(ViewStub stub, View inflated)
                {

                    setUIElements(inflated, tempHistoryList);
                }
            });
            historyContainer.addView(viewStub);
            viewStub.inflate();


        }


        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    });

    setViewStub();
}


/********************************************************************************************************/
private void setViewStub()
{
    historyList.add("first");
    historyList.add("second");
    historyList.add("third");
    historyList.add("fourth");
    historyList.add("fifth");
    historyList.add("sixth");
    historyList.add("seventh");


    viewStub = new ViewStub(TestFilterListView.this, R.layout.history_schedule);
    viewStub.setOnInflateListener(new ViewStub.OnInflateListener()
    {
        public void onInflate(ViewStub stub, View inflated)
        {

            setUIElements(inflated, historyList);


















        }
    });
    historyContainer.addView(viewStub);
    viewStub.inflate();



}



/********************************************************************************************************/
final List<String> historyList = new ArrayList<String>();
String displayName = "";
ListView historyListView;
private void setUIElements(View v, List<String> historyLists)
{


    if (v != null)
    {
        historyScheduleData.clear();
        //historyList.clear();

        historyScheduleData.addAll(historyLists);
        historyListView = (ListView) findViewById(R.id.historylist);
        historyListView.setAdapter(new BeatListAdapter(this));

        registerForContextMenu(historyListView);


    }


}

private static class BeatListAdapter extends BaseAdapter {
    private LayoutInflater mInflater;

    public BeatListAdapter(Context context) {
        mInflater = LayoutInflater.from(context);

    }

    public int getCount() {
        return historyScheduleData.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.history_list_view, null);
            holder = new ViewHolder();
            holder.historyData = (TextView) convertView
                    .findViewById(R.id.historytext);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.historyData.setText(historyScheduleData.get(position));

        return convertView;
    }

    static class ViewHolder {

        TextView historyData;
    }
}

private static final List<String> historyScheduleData = new ArrayList<String>();

}

I thought about using

protected void onListItemClick(ListView l, View v, int position, long id) {

        if(position == 0) {
            Intent intent = new Intent(getApplicationContext(), GODoc1Activity.class);
            startActivity(intent);

But when I try to implement it, it does not work. Am I missing something here? How do I go about doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:44:33+00:00Added an answer on June 17, 2026 at 7:44 pm

    you tried this?: (in the onCreate)

    historyListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
                //your code
    
                }
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was microbenchmarking some code (please be nice) and came across this puzzle: when
I just came across Niceforms and they look..well, nice. I was wondering if anyone
Came across a code, and was wondering why this works? $.fn.appendVal = function(txt) {
I came across this really nice looking Scala code while researching XMPP for a
I just came a cross this nice code that makes this scatter matrix plot:
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
Came across something like this today, and was wondering if there was an equivalent
I came across this Linq to Sql code in an application I am maintaining:
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I came across this due to a bug in my code and I'm curious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.