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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:17:03+00:00 2026-06-16T09:17:03+00:00

I’ve created a listview with its own adapter, but now I have to implement

  • 0

I’ve created a listview with its own adapter, but now I have to implement the setOnClickListener method?
Reading my manual and searching on the net I’ve seen that it doesnt work normally in this case, can someone explain me how to use it properly, maybe with a example?

This is my MainActivity.java

package com.gabriele.progetti;


import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.res.AssetManager;
import android.graphics.Typeface;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity 
{
    TextView textview;
    ListView menu;
    final static String[] Scelte = new String[] {"Una citazione a caso", "Cerca per autore", "Cerca per categoria", "Crediti"};

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /* Comincio tutti i magheggi per prendere il font e settarlo */
        AssetManager assetManager = getResources().getAssets();
        Typeface typeface = Typeface.createFromAsset(assetManager, "fonts/stilo.otf");
        textview = (TextView) findViewById(R.id.textView1);
        textview.setTypeface(typeface);
        /* Magheggi finiti */

        menu = (ListView) findViewById(R.id.listView1);
        //SetAdapter e non setlistAdapter perchè non sto usando ListActivity.
        // Gli passo la classe MenuAdapter con un context proprio e la stringa Scelte.
        menu.setAdapter(new MenuAdapter(this, Scelte)); 

    }


}

And this is my MenuAdapter.java

package com.gabriele.progetti;

import java.util.List;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MenuAdapter extends ArrayAdapter<String>
{
    private final Context context;
    private final String[] valori;

    public MenuAdapter(Context context, String[] valori) 
    {
        // TODO Auto-generated constructor stub
        super(context, R.layout.activity_main, valori);
        this.context = context;
        this.valori = valori;

    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
         // Dico al service di Android di prepararsi ad una animazione (inflate = animare).
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        // Prendo tutte le View all'interno del file XML row_modificata e le metto nella ViewAnimata.
        View ViewAnimata = inflater.inflate(R.layout.row_modificata, parent, false);

        // Dichiaro un context perchè in un arrayadapter se voglio prendere un asset devo utilizzarlo per forza.
        Context context1 = context;
        AssetManager assetManager = context1.getResources().getAssets();

        TextView textView = (TextView) ViewAnimata.findViewById(R.id.textView2);
        Typeface typeface = Typeface.createFromAsset(assetManager, "fonts/menu.ttf");
        textView.setTypeface(typeface);
        textView.setText(valori[position]); // Assegno un testo per ogni valore presente nella stringa che passo.

        return ViewAnimata;

    }

Thank you!

  • 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-16T09:17:04+00:00Added an answer on June 16, 2026 at 9:17 am

    Add this code in MainActivity:

        menu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                Toast.makeText(activity, "Pressed " + position, Toast.LENGTH_SHORT).show();
    
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a small JavaScript validation script that validates inputs based on Regex. I

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.