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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:02:46+00:00 2026-05-24T06:02:46+00:00

i have problem with listview… i’m trying to add OnClickListener but in still doesn’t

  • 0

i have problem with listview… i’m trying to add OnClickListener but in still doesn’t work. I want to display another activity after click. Can somebody help me? I know that there are many of example, but it’s doesn’t work for my appl or i don’t know how to use it in my example…

This is my LocationAdapter class:

public class LocationAdapter extends ArrayAdapter<LocationModel> {

int resource;
String response;
Context context;
private LayoutInflater mInflater;

public LocationAdapter(Context context, int resource, List<LocationModel> objects) {
    super(context, resource, objects);
    this.resource = resource;
    mInflater = LayoutInflater.from(context);
}

static class ViewHolder {
    TextView titleGameName;
    TextView distanceGame;
        }


public View getView(int position, View convertView, ViewGroup parent)
{
    ViewHolder holder;
    //Get the current location object
    LocationModel lm = (LocationModel) getItem(position);

    //Inflate the view
    if(convertView==null)
    {
        convertView = mInflater.inflate(R.layout.item, null);
        holder = new ViewHolder();
        holder.titleGameName = (TextView) convertView
                .findViewById(R.id.it_location_title);
        holder.distanceGame = (TextView) convertView
                .findViewById(R.id.it_location_distance);

        convertView.setTag(holder);   


     } else  {

         holder = (ViewHolder) convertView.getTag();

    }

    holder.titleGameName.setText(lm.getGameName());
    holder.distanceGame.setText(lm.getGameDistance()+" km");

    return convertView;
}

}

This is my mainListView class:

public class SelectGameActivity extends Activity {
LocationManager lm;
GeoPoint userLocation;

ArrayList<LocationModel> locationArray = null;
LocationAdapter locationAdapter;
LocationList list;

ListView lv;
TextView loadingText;
TextView sprawdz;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.selectgame);

    lv = (ListView) findViewById(R.id.list_nearme);

    locationArray = new ArrayList<LocationModel>();
    locationAdapter = new LocationAdapter(SelectGameActivity.this, R.layout.item, locationArray);


    lv.setTextFilterEnabled(true);
    lv.setAdapter(locationAdapter);
    lv.setItemsCanFocus(true);





    String serverName = getResources().getString(R.string.serverAdress);
    ApplicationController AC = (ApplicationController)getApplicationContext();
    String idPlayer = AC.getIdPlayer();
    int latitude = AC.getCurrentPositionLat();
    int longitude = AC.getCurrentPositionLon();
    int maxDistance = 99999999;


    try {
        new LocationSync().execute("myserverName");
    } catch(Exception e) {}







}


//this is connection with json
private class LocationSync extends AsyncTask<String, Integer, LocationList> {

    protected LocationList doInBackground(String... urls) {
        LocationList list = null;
        int count = urls.length;

        for (int i = 0; i < count; i++) {
            try {           
                // ntar diganti service
                RestClient client = new RestClient(urls[i]);

                try {
                    client.Execute(RequestMethod.GET);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                String json = client.getResponse();

                list = new Gson().fromJson(json, LocationList.class);

                //
            } catch(Exception e) {}
        }
        return list;
    }

    protected void onProgressUpdate(Integer... progress) {

    }

    protected void onPostExecute(LocationList loclist) {

        for(LocationModel lm : loclist.getLocations())
        {
            locationArray.add(lm);
        }
        locationAdapter.notifyDataSetChanged();
    }

}

EDIT:: I have second problem… i want to get id from item (items are downloading from json url) This is my list:

enter image description here

I want to get for example: ID:159 for first item and send it to nextActivity.

I have also the controllerClass.java where i’m setting and getting selectedIdGame:

    public String getIdGameSelected() {

    return idGame;
}

public void setIdGameSelected(String idGame) {

    this.idGame = idGame;
}

Is it good idea? Thanks for help.

Ok, it’s done. i used:

   public void onItemClick(AdapterView<?> a, View
                                v, int position, long id) {


            String idGame = (String) ((TextView) v.findViewById(R.id.idGameSelected)).getText();

Thanks, Michal.

  • 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-05-24T06:02:47+00:00Added an answer on May 24, 2026 at 6:02 am

    You could define an onItemClick on your adapter instance (i.e. in mainListView.java, just after lv.setAdapter):

    lv.setOnItemClickListener(new OnItemClickListener() {
                    public void onItemClick(AdapterView<?> a, View
                                            v, int position, long id) {
                        Intent i = new Intent(v.getContext(), NextActivity.class);
                        startActivity(i);
                    }
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem. I want to add image to listView. Exactly I want
I have another problem with ListView :( Now I need to move items in
I use a ListView for text-items in my APP. But I have one problem:
i have a problem i want to add Colomn ( Dynamic using C #)
I have a problem; I am trying to make a listview in C# Forms
I have a problem refreshing a ListView. I call my ListView Activity , I
I have the following problem. The background color in a ListView is set LightGreen
I have an activity which consists of a ListView . The problem is that
I have problem with fancybox. I want to write a function that will run
I have problem in ListView MultiSelection. Here is my code : private ICommand _excludeCurveCommand;

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.