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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:08:04+00:00 2026-06-14T21:08:04+00:00

I am working on a listview that when you click an item, it shows

  • 0

I am working on a listview that when you click an item, it shows an alertdialog with 2 options, and after they pick an option it takes them back to the listview where they can do it again with another selection. For some reason once I click an item, if I click the positive button (the one with code in it) then try and click on another item the alert dialog doesn’t pop up. Does anyone know why this would happen? The code is below:

protected void onListItemClick(ListView l, View v, int position, long id) {
        final int i = position;
        try {
            new AlertDialog.Builder(this)
            .setTitle("Download")
            .setMessage("You have selected the level " + jArray.getJSONObject(i).getString("level_name") + ". Would you like to save it?")
            .setPositiveButton("Save", new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        saveLevel(jArray.getJSONObject(i).getString("level_name"),jArray.getJSONObject(i).getInt("id"));
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    return;
                } 
            })
            .setNegativeButton("Cancel",new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int which) {
                    return;
                } 
            })
            .show();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        super.onListItemClick(l, v, position, id);
    }

If you need anything other info let me know! Thanks in advance!

William

Edit

From what I can tell, it is happening in the saveLevel function, I am posting it below

public void saveLevel(String i, int id)
{
    InputStream is = null;
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("uid","demo"));
    String result = "";
    try
    {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("www.example.com/stuff.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        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();
        jArray = new JSONArray(result);
        File exst = Environment.getExternalStorageDirectory();
        String exstPath = exst.getPath();

        File filePath = new File(exstPath+"/Platformer/Downloaded");
        boolean success = filePath.mkdir();
        String path = filePath.getAbsolutePath() + "/" + i + ".xml";
        File newxmlfile = new File(path);
        try 
        {
            newxmlfile.createNewFile();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();

        }
        FileOutputStream fileos = null;        
        try
        {
            fileos = new FileOutputStream(newxmlfile);
        }
        catch(FileNotFoundException e)
        {
            Log.e("FileNotFoundException", "can't create FileOutputStream");
            return;
        }
        OutputStreamWriter output = new OutputStreamWriter(fileos);
        output.write(jArray.getJSONObject(0).getString("level_data"));
        output.flush();
        output.close();
    }
    catch(Exception e)
    {
        Log.e("log_tag", "Error parsing data "+e.toString());
    }
}
  • 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-14T21:08:05+00:00Added an answer on June 14, 2026 at 9:08 pm

    Your saveLevel() function does a lot of things (network access, file access), that are not suited well for UI thread. You should separate these things into a background thread, preferably using AsyncTask (tutorial).

    Most probably your program is still stuck in saveLevel() when you’re trying to click another list item. If you want to check if this assumption is really true, just put a return; line in the beginning of saveLevel() and see if your dialog box pops up as intended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with expandable listview. In that I need to use click-able imageview. I've
This Question has been modified to show working code. When they click an item
I have a ListView that displays a shopping cart. It was working fine until
I'm working with a winForms app that has a listView. That listView has multi-select
I have one listview that compiles layout template, item template and insert item template.
My project contains listView(homelistView) that contains button(btnList) . When I click on button(btnList) it
I want to change background color of selected item in listview. When I click
I am making a custom listview, in that data is dynamically changing after sometime.
OK, I am working on an App that has a page with a listview
I am working on some ListView I want to display a Button under it

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.