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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:29:31+00:00 2026-06-15T23:29:31+00:00

I have changed this class extends with Acitvity and before that it was extends

  • 0

I have changed this class extends with Acitvity and before that it was extends with ListActivity, this is because I like to use setEmptyView for this class. But after I changed this class extends with Activity, its list items couldn’t pop out the dialog when it’s clicked.Could anyone give some advices?

ThirdActivity.java

public class ThirdActivity extends Activity{
Bundle b;
String user,line,result,datapassed,list;
DefaultHttpClient httpclient;
HttpPost httppost;
HttpResponse response;
InputStream is = null;
BufferedReader reader;
StringBuilder sb;
ArrayList<NameValuePair> nameValuePairs;
ListView lv;
IntentFilter intentFilter;
int notification = 1;
String str = "";
byte[] data;
int dlength;
String[] item = {"Track Location","Remove Friend"};
ArrayAdapter<String> adapter;
ArrayList<String> friend;
TextView emptyText;    

    public void onCreate(Bundle savedInstancesState)
    {
    super.onCreate(savedInstancesState);
    setContentView(R.layout.list_screen);
    user = getIntent().getExtras().getString("user");
    Log.d("dg",user);
    lv = (ListView) findViewById(R.id.list);
    emptyText = (TextView)findViewById(R.id.empty);
    getList();                
    }
    }

    public void getList(){
    new Thread(){
        public void run(){
            try{
                 httpclient = new DefaultHttpClient();
                 httppost = new HttpPost("http://www.kryptoquest.com/tracker/friendlist.php");
                 ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
                 nameValuePairs.add(new BasicNameValuePair("Username", user));
                 httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                 response = httpclient.execute(httppost);
                 is = response.getEntity().getContent();
            }catch(Exception e){
                Log.e("log_tag", "Error:"+e.toString());
            }

            //convert response to string
            try{
                    reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                    sb = new StringBuilder();
                    line = null;
                    while ((line = reader.readLine()) != null) {

                            sb.append(line + "\n");

                    }
                    Log.d("test",sb.toString());
                    is.close();

                    result = sb.toString();

                    result = result.substring(0, result.length()-1);                    
                //    Log.d("result",result);
                    friend = new ArrayList<String>(Arrays.asList(result.split("[*]")));   
                  Log.d("size",String.valueOf(friend.size()));
                    runOnUiThread(new Runnable()
                    {
                        public void run(){
                            adapter = new ArrayAdapter<String>(ThirdActivity.this,android.R.layout.simple_list_item_1,friend);
                            lv.setAdapter(adapter); 
                            lv.setEmptyView(emptyText);
                        }
                    });


            }catch(Exception e){
                    Log.e("log_tag", "Error converting result "+e.toString());
            }
        }
    }.start();
 }

 public void onItemClick( View v, final int position, long id){       
        AlertDialog.Builder adb = new AlertDialog.Builder(ThirdActivity.this);
               adb.setItems(item, new DialogInterface.OnClickListener() {                   
               public void onClick(DialogInterface dialog, int which) {                    
                   Toast.makeText(ThirdActivity.this, item[which], Toast.LENGTH_LONG).show();  
                   if(item[which].equals("Track Location")){
                       AlertDialog.Builder adb = new AlertDialog.Builder(
                            ThirdActivity.this);
                            adb.setIcon(R.drawable.location);
                            adb.setTitle("Friend Location");
                            adb.setMessage("Do you want to track "
                            + lv.getItemAtPosition(position) + "'s location?");
                            adb.setPositiveButton("Yes", 
                                    new DialogInterface.OnClickListener(){
                                        public void onClick(DialogInterface dialog, int whichButton)
                                        {
                                            new Thread(){
                                                public void run(){
                                                    try{
                                                         httpclient = new DefaultHttpClient();
                                                         httppost = new HttpPost("http://www.kryptoquest.com/tracker/track.php");
                                                         nameValuePairs = new ArrayList<NameValuePair>(2);
                                                         Log.d("12345678",user); 
                                                         nameValuePairs.add(new BasicNameValuePair("Targetname", (String) lv.getItemAtPosition(position)));
                                                         Log.d("Targetname",(String) lv.getItemAtPosition(position));
                                                         nameValuePairs.add(new BasicNameValuePair("Username", user));
                                                         httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                                                         response = httpclient.execute(httppost);
                                                         is = response.getEntity().getContent();
                                                    }catch(Exception e){
                                                        Log.e("log_tag", "Error:"+e.toString());
                                                    }

                                                    //convert response to string
                                                    try{
                                                            reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                                                            sb = new StringBuilder();
                                                            line = null;
                                                            while ((line = reader.readLine()) != null) {

                                                                    sb.append(line + "\n");

                                                            }
                                                            Log.d("test",sb.toString());
                                                            is.close();

                                                            result = sb.toString();
                                                            Intent i = new Intent(ThirdActivity.this,Map.class);
                                                            i.putExtra("location", result);
                                                            startActivity(i);                                                                                                                                                                               

                                                    }catch(Exception e){
                                                            Log.e("log_tag", "Error converting result "+e.toString());
                                                    }
                                                }
                                            }.start();

                                        }
                            });
                            adb.setNegativeButton("No", null);
                            adb.show(); 
                   }else{
                       AlertDialog.Builder adb=new AlertDialog.Builder(ThirdActivity.this);
                       adb.setTitle("Delete?");
                       adb.setMessage("Are you sure you want to delete " + (String) lv.getItemAtPosition(position));
                       Log.d("index", String.valueOf(position));
                       adb.setNegativeButton("Cancel", null);
                       adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
                           String delete = (String) ((lv.getAdapter()).getItem(position));
                           public void onClick(DialogInterface dialog, final int which) {
                            //  lv.invalidateViews();                                                               
                               new Thread(){
                                    public void run(){
                                        try{
                                             httpclient = new DefaultHttpClient();
                                             httppost = new HttpPost("http://www.kryptoquest.com/tracker/remove.php");
                                             nameValuePairs = new ArrayList<NameValuePair>(2);
                                             Log.d("12345678",user); 
                                             nameValuePairs.add(new BasicNameValuePair("Targetname", (String) lv.getItemAtPosition(position)));
                                             nameValuePairs.add(new BasicNameValuePair("Username", user));
                                             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                                             response = httpclient.execute(httppost);
                                             is = response.getEntity().getContent();

                                             data = new byte[256];

                                            StringBuffer buffer = new StringBuffer();
                                            int len = 0;     //100 
                                            while (-1 != (len = is.read(data)) )
                                            {
                                              buffer.append(new String(data, 0, len));

                                            } 
                                              Log.d("MainActivity", buffer.toString());
                                              if(buffer.charAt(0)=='Y')
                                              {

                                                 runOnUiThread(new Runnable()
                                                   {
                                                       public void run()
                                                       {   

                                                         Toast.makeText(ThirdActivity.this, (String)lv.getItemAtPosition(position)+" has removed from friendlist", Toast.LENGTH_LONG).show();
                                                         friend.remove(delete);
                                                         adapter.notifyDataSetChanged();    
                                                       }
                                                   });

                                              }
                                              else
                                              {
                                                 runOnUiThread(new Runnable()
                                                   {
                                                       public void run()
                                                       {
                                                         Toast.makeText(ThirdActivity.this, "Friend remove failed", Toast.LENGTH_LONG).show();
                                                       }
                                                   });
                                              }


                                          is.close();
                                        }catch(Exception e){
                                            Log.e("log_tag", "Error:"+e.toString());
                                        }                                           

                                    }
                                }.start();                                    

                           }});
                       adb.show();
                   }
               }  
        });  
         AlertDialog ad = adb.create(); 
         ad.show();       
    }

list_screen.xml

 <?xml version="1.0" encoding="UTF-8"?>

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >

 <ListView android:id="@+id/list"
      android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>


<TextView   android:id="@+id/empty"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:text="@string/no_friend"
            android:gravity="center_vertical|center_horizontal"
            />

 </LinearLayout>
  • 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-15T23:29:32+00:00Added an answer on June 15, 2026 at 11:29 pm

    Its because you are haven’t set OnItemClickListener to ListView. So, your onItemClick() is never called. You have to set OnItemClickListener to ListView explicitly when you are extending your Activity as Activity and not ListActivity.

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

Sidebar

Related Questions

This was working last night, but I must have accidentally changed something, because it
I have an imageview that should be changed on click public class Settings extends
I have searched the numerous questions that look like this one, but haven't found
I know this code use to work, I must have accidentally changed something when
If I have a listener for changed tab like this: mTabHost.setOnTabChangedListener(new OnTabChangeListener() { public
So I have this asp.net web application that I renamed. I changed the assembly
I have already posted a question about this, but the situation has changed sufficiently
I have a class ActivityExitDialogFragment that extends android.support.v4.app.DialogFragment. There are only 2 methods in
I have a problem, I need to change body of method when this class
I have this written, but the animations are colliding. How to changes this to

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.