Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello android enthusiasts

1. How can I add filter to a search framework in my app
2. How can I make the search result scroll by dynamically adding scrollviewer
3. How to populate the search keywords and result from text files in assets/raw folder
See the code below
Java
MAINACTIVITY
public class MainActivity extends ActionBarActivity {

    Button btnSearch;
    private Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        toolbar = (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
        setSupportActionBar(toolbar);

        Button btnSearch = (Button) findViewById(R.id.btnSearch);
        btnSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                onSearchRequested();
            }
        });
    }
SEARCHACTIVITY
public class SearchActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        Map<string,string> map = new Hashtable<string,string>();
        map.put("Salam","Hello in arabic");//How to read/populate search result from text files in asseta folder
        map.put("Bonjour", "Hello in french");//How to read/populate search result from text files in asseta folder
        map.put("Hola", "Hello In Spanish");//How to read/populate search result from text files in asseta folder
        String result = "Found Nothing!";
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        if (Intent.ACTION_SEARCH.equals(intent.getAction()))
        {
            String query = intent.getStringExtra(SearchManager.QUERY);
            Log.i("search","query="+query);
            String str = map.get(query);
            if (str!=null)
            {
                result = "result: "+query+" is "+str;
            }
        }
        TextView text = new TextView(this);
        text.setText(result);
        text.setTextSize(20);
        text.setGravity(Gravity.CENTER | Gravity.CENTER_HORIZONTAL);
        setContentView(text);
        text.setVerticalScrollBarEnabled(true);
        text.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        text.setSingleLine(false);


    }

Kindly help
Posted
Updated 9-Aug-15 14:29pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900