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

  • SEARCH
  • Home
  • 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 8517611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:45:06+00:00 2026-06-11T05:45:06+00:00

I have a code for dictionary application. If user click list item in the

  • 0

I have a code for dictionary application. If user click list item in the search box,i want to show dialog box with two buttons.. But i tested in emulator it won’t appear. I used following code for creating dictionary application.This is MainActivity calss only.

MyCode:

public class Shower extends Activity {
     private TextView mTextView;
        private ListView mListView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shower);

        mTextView = (TextView) findViewById(R.id.text);
        mListView = (ListView) findViewById(R.id.list);

        handleIntent(getIntent());
    }


    @Override
    protected void onNewIntent(Intent intent) {
        // Because this activity has set launchMode="singleTop", the system calls this method
        // to deliver the intent if this actvity is currently the foreground activity when
        // invoked again (when the user executes a search from this activity, we don't create
        // a new instance of this activity, so the system delivers the search intent here)
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        if (Intent.ACTION_VIEW.equals(intent.getAction())) {
            // handles a click on a search suggestion; launches activity to show word
            Intent wordIntent = new Intent(this, WordActivity.class);
            wordIntent.setData(intent.getData());
            startActivity(wordIntent);
            finish();
        } else if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            // handles a search query
            String query = intent.getStringExtra(SearchManager.QUERY);
            showResults(query);
        }
    }

    /**
     * Searches the dictionary and displays results for the given query.
     * @param query The search query
     */
    private void showResults(String query) {

        Cursor cursor = managedQuery(DictionaryProvider.CONTENT_URI, null, null,
                                new String[] {query}, null);

        if (cursor == null) {
            // There are no results
            mTextView.setText(getString(R.string.no_results, new Object[] {query}));
        } else {
            // Display the number of results
            int count = cursor.getCount();
            String countString = getResources().getQuantityString(R.plurals.search_results,
                                    count, new Object[] {count, query});
            mTextView.setText(countString);

            // Specify the columns we want to display in the result
            String[] from = new String[] { DictionaryDatabase.KEY_WORD,
                                           DictionaryDatabase.KEY_DEFINITION };

            // Specify the corresponding layout elements where we want the columns to go
            int[] to = new int[] { R.id.word,
                                   R.id.definition };

            // Create a simple cursor adapter for the definitions and apply them to the ListView
            SimpleCursorAdapter words = new SimpleCursorAdapter(this,
                                          R.layout.result, cursor, from, to);
            mListView.setAdapter(words);

            // Define the on-click listener for the list items
            mListView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    // Build the Intent used to open WordActivity with a specific word Uri
                   // Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
                    //Uri data = Uri.withAppendedPath(DictionaryProvider.CONTENT_URI,
                                                   // String.valueOf(id));
                   // wordIntent.setData(data);
                    //startActivity(wordIntent);



            String title="Dictionary";
            String message="definition";
            AlertDialog.Builder dialog = new AlertDialog.Builder(Shower.this);
               dialog.setTitle(title);
               dialog.setMessage(message);             


                 dialog.setCancelable(false);
                 dialog.setPositiveButton("Dictionary",
                  new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {


                         Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
                         Uri data = Uri.withAppendedPath(DictionaryProvider.CONTENT_URI,
                                                         String.valueOf(id));
                         wordIntent.setData(data);
                         startActivity(wordIntent);

                     }
                 }) ;

                 dialog.setNegativeButton("definition", 
                  new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
                         dialog.dismiss();
                     }
                 });
                 dialog.show();
                }


                });
        }
        }




    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //getMenuInflater().inflate(R.menu.activity_shower, menu);
      //  return true;

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.activity_shower, menu);

        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);

        return true;

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.search:
                onSearchRequested();
                return true;
            default:
                return false;
        }
    }
}
  • 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-11T05:45:07+00:00Added an answer on June 11, 2026 at 5:45 am

    Try this:

             AlertDialog dialog = new AlertDialog.Builder(YourClassName.context).create();
        dialog.setTitle("");
        dialog.setMessage("");
    
       dialog.setIcon("");
      dialog.setButton(DialogInterface.BUTTON_POSITIVE,"Open whatever", new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog, int which) {
                                    // TODO Auto-generated method stub 
    Intent intent = new Intent(YourClassName.context, OtherClassName.class);
            //your code ....
                    }   
                    });
    
               dialog.show();
    
    
         return true;
    
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: // Dictionary which I want to optimize Dictionary<string, MyClass>
In my application,I do not want two user login with the same login name.
I have some code that sets up a dictionary with some defualt values for
I have written a code for adding multiple keys for a dictionary for that
I have a Dictionary bound to DataGridView by using following sample code. DataGridView bound
I have code that generates a List<string[]> variable but can't quite figure out how
I have code which has a drop down list. And when a certain option
I have some code that locates all the contact folders that a user has
I have a resource dictionary of localized strings. I want to set a property
I have .NET WPF application and one of requirement is that user may select

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.