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 7747775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:36:48+00:00 2026-06-01T10:36:48+00:00

Who would of thought getting a dialog box to show would be so difficult.

  • 0

Who would of thought getting a dialog box to show would be so difficult. In C# it is so easy. I’ve looked all over line for help and every tip seems to cause me trouble than good. Can someone please look at the below code and tell me where I might have gone wrong?

What I want is very simple. User clicks button. Then list appears. Then user clicks on one of the items in list, and dialogue appears. The code in onItemClick in the listview event is from someone else. It apparently works for that person. I keep clicking and seeing nothing. I’m open to suggestions on how to fix it, or new code all together. Sorry, the log has no error messages.

Please be specific about where I put the code as I’m an Android noob. And thank you in advance!

public class SetPrediction extends Activity
{
    Button btnInsrt, btnFTeam, btnSTeam;
    ArrayList<NameValuePair> nameValuePairs;
    TextView txtGameTeams;
    Bundle recdData;
    String game;

    JSONArray jArray;
    String result;
    InputStream is;
    StringBuilder sb;

    ArrayList<String> fNames;
    ListView listView;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.set_prediction);

        nameValuePairs = new ArrayList<NameValuePair>();
        txtGameTeams = (TextView) findViewById(R.id.txtGameTeams);

        recdData = getIntent().getExtras(); 
        game = recdData.getString("xxxx.xxxx.xxx");
        txtGameTeams.setText("xxxxxxx: " + game + " game.");

        btnInsrt = (Button) findViewById(R.id.btnInsert);
        btnFTeam = (Button) findViewById(R.id.btnFirstTeam);
        btnSTeam = (Button) findViewById(R.id.btnSecondTeam);

        btnFTeam.setText(removeSpaces(game.split("vs")[0]));
        btnSTeam.setText(removeSpaces(game.split("vs")[1]));

        btnSTeam.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View v) 
            {
                String result = "";
                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
                nameValuePairs.add(new BasicNameValuePair("players", removeSpaces(game.split("vs")[1])));

                fNames = new ArrayList<String>();
                listView = (ListView) findViewById(R.id.lstPlayerForPrediction);

                //http post
                try
                {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("http://xxxxx/getTeamPlayers.php");
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    HttpResponse response = httpclient.execute(httppost); 
                    HttpEntity entity = response.getEntity();
                    InputStream is = entity.getContent();

                    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                    StringBuilder sb = new StringBuilder();
                    String line = null;
                    while ((line = reader.readLine()) != null) 
                    {
                        sb.append(line + "\n");
                    }
                    is.close();

                    result=sb.toString();
                }
                catch(Exception e)
                {
                    Log.e("log_tag", "Error in http connection " + e.toString());
                }

                //parse json data
                try
                {
                    JSONArray jArray = new JSONArray(result);
                    for(int i=0;i<jArray.length();i++)
                        fNames.add(jArray.getJSONObject(i).getString("First_Name"));  

                }
                catch(JSONException e)
                {
                    Log.e("log_tag", "Error parsing data " + e.toString());
                }

                ArrayAdapter<String> adapter = new ArrayAdapter<String>(SetPrediction.this, android.R.layout.simple_list_item_1, fNames);
                listView.setAdapter(adapter);

                listView.setOnItemClickListener(new OnItemClickListener()
                {
                    public void onItemClick(AdapterView<?> arg0, View predictView, int item, long arg3) 
                    {
                        final CharSequence[] items = {"Online", "Away", "Do not distrub","Invisible","Offline"}; 
                        AlertDialog.Builder builder = new AlertDialog.Builder(SetPrediction.this); 


                        builder.setTitle("Change Status"); 
                        builder.setItems(items, new DialogInterface.OnClickListener() 
                        { 
                            public void onClick(DialogInterface dialog, int item) 
                            { 
                                Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); 
                            } 
                        });

                        AlertDialog alert = builder.create(); 
                        alert.show();
                    } 
                });
            }
        });
    }


    public String removeSpaces(String s) 
    {  
        StringTokenizer st = new StringTokenizer(s," ",false);
        String t="";
        while (st.hasMoreElements()) t += st.nextElement();
        return t;
    }

The problem is in the listView.setOnItemClickListener(new OnItemClickListener() event. That the part that doesn’t work.

  • 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-01T10:36:49+00:00Added an answer on June 1, 2026 at 10:36 am

    Check out this:

    public void showAlertDialog(String title, String message, Context context)
    {
        final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    
        alertDialog.setTitle(title);
        alertDialog.setMessage(message);
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                alertDialog.dismiss();
            }
        });
    
        alertDialog.show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an iPhone application for car dealers who would register with my
I was recently approached by a network-engineer, co-worker who would like to offload his
How would you explain to someone who has just started programming in Java, what
I would like to give points to my users who submit articles based on
I would like a message to be shown to users who enter on my
I would like to know the process and service providers who will enable me
I have some clients who are not English speaking. They would like the JavaScript
Once again my silliness has struck. I would like to thank everyone who helped
I'm looking on who to customize the serialization of an attribute. I thought it
As someone who comes from the world of Object Orientation, I find it rather

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.