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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:06:07+00:00 2026-06-03T05:06:07+00:00

i need to be able to make calls from an activity. so here is

  • 0

i need to be able to make calls from an activity. so here is a my activity that shows details of people and i have a call button. but i get a nullPointerError when i call the setOnClickListener(…). why? thnks for any help.

package com.AndroidApp.pagine;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import com.AndroidApp.ApplicationController;
import com.AndroidApp.R;
import com.AndroidApp.XMLFunctions;
import com.AndroidApp.Login.LoginActivity;
import com.AndroidApp.domain.Anagrafica;



public class DettagliPagina extends ListActivity {

    public Anagrafica anagrafica;
    public ArrayList<HashMap<String, String>> mylist;
    private boolean paused, newIntentSelected = false;  
    private ProgressDialog progressDialog;
    private SharedPreferences mPreferences;
    public ApplicationController ac;

    private Button bCall;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        ac = (ApplicationController)getApplication();

        mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE);
        String nome = mPreferences.getString("nome", "Errore");
        String cognome = mPreferences.getString("cognome", "Errore");
        setTitle("Sessione di : " + nome + " " + cognome);

        new BackgroundAsyncTask().execute();
    }


    @Override
    protected void onStart() {
        super.onStart();


        bCall = (Button) findViewById(R.id.bCall);

        // add PhoneStateListener
        PhoneCallListener phoneListener = new PhoneCallListener();
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

        // add button listener
        bCall.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {

                    Intent callIntent = new Intent(Intent.ACTION_CALL);
                    callIntent.setData(Uri.parse("tel:3492395504"));
                    startActivity(callIntent);

                }
        }); 

    }



    @Override
    protected void onPause() {
        super.onPause();
        paused = true;
        ac.setOraAttuale(Calendar.getInstance());
        ac.oraAttuale.add(Calendar.MINUTE, 1);
        ac.setOraScadenza(ac.getOraAttuale());
        Log.d("DettagliPAgina scadenza", ac.getOraScadenza().getTime().toString());
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (ac.isKill) {
            finish();
        }
        if (paused && !newIntentSelected){
            if (Calendar.getInstance().after(ac.getOraScadenza())){
                //torna al login con toast sessione scaduta
                ac.setSessioneTerminata(true);
                Toast.makeText(getApplicationContext(), "Sessione Scaduta", Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(DettagliPagina.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }
        }
    }


    public class BackgroundAsyncTask extends
            AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {

        @Override
        protected ArrayList<HashMap<String, String>> doInBackground(
                String... paths) {
            mylist = new ArrayList<HashMap<String, String>>();

            String xml = XMLFunctions.getXML();
            Document doc = XMLFunctions.xmlFromString(xml);
            int numResults = XMLFunctions.numResults(doc);

            if ((numResults <= 0)) {
                Log.i("doInBack", "nussun risultato");
                DettagliPagina.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(getApplicationContext(), "Nessun risultato trovato", Toast.LENGTH_LONG).show();
                    }
                });

                Intent intent = new Intent(DettagliPagina.this, FiltriAnagraficaPagina.class);
                startActivity(intent);
            }

            Bundle extras = getIntent().getExtras();
            int id = 0;
            System.out.print(id);
            if (extras != null) {
                id = extras.getInt("id");
            }

            Log.i("Dettagli", "D1");
            Set<Anagrafica> anagrafici = new HashSet<Anagrafica>();
            NodeList nodes = doc.getElementsByTagName("anagrafica");    

            Element e = (Element) nodes.item(id);
            anagrafica = new Anagrafica();
            anagrafica.setId(XMLFunctions.getValue(e, "idAnagrafica"));
            anagrafica.setNome(XMLFunctions.getValue(e, "nome"));
            anagrafica.setCognome(XMLFunctions.getValue(e, "cognome"));
            anagrafica.setIndirizzo(XMLFunctions.getValue(e, "indirizzo"));
            anagrafica.setDataDiNascita(XMLFunctions.getValue(e, "dataDiNascita"));
            anagrafica.setEmail(XMLFunctions.getValue(e, "email"));
            anagrafica.setTipologiaUtente(XMLFunctions.getValue(e, "tipologieUtente"));
            anagrafica.setAziendaCollegata(XMLFunctions.getValue(e, "aziendaCollegata"));
            anagrafica.setTelefono(XMLFunctions.getValue(e, "telefono"));
            anagrafica.setCellulare(XMLFunctions.getValue(e, "cellulare"));
            anagrafica.setInteressi(XMLFunctions.getValue(e, "interessi"));
            anagrafica.setRiferimenti(XMLFunctions.getValue(e, "riferimenti"));
            anagrafici.add(anagrafica);

            HashMap<String, String> map = new HashMap<String, String>();
            map.put("idAnagrafica",anagrafica.getId());
            map.put("nomeCognome",anagrafica.getNome() + " " + anagrafica.getCognome());
            map.put("indirizzo", "Indirizzo: " + anagrafica.getIndirizzo());
            map.put("dataDiNascita", "Data Nascita: " + anagrafica.getDataDiNascita());
            map.put("email", "Email: " + anagrafica.getEmail());
            map.put("tipologieUtente", "Tipologie Utente: " + anagrafica.getTipologiaUtente());
            map.put("aziendaCollegata", "Azienda Collegata: " + anagrafica.getAziendaCollegata());
            map.put("telefono", "Telefono: " + anagrafica.getTelefono());
            map.put("cellulare", "Cellulare: " + anagrafica.getCellulare());
            map.put("interessi", "Interessi: " + anagrafica.getInteressi());
            map.put("riferimenti", "Riferimenti" + anagrafica.getRiferimenti());

            mylist.add(map);
            Log.i("Dettagli", "D2");
            return mylist;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressDialog = new ProgressDialog(DettagliPagina.this);
            progressDialog.setCancelable(true);
            progressDialog.setMessage("Loading...");
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.setProgress(0);
            progressDialog.show();
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
        }

        protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

            final ListAdapter adapter = new SimpleAdapter(DettagliPagina.this,  mylist, R.layout.dettagli,
                    new String[] { "nomeCognome", "dataDiNascita",
                            "tipologieUtente", "aziendaCollegata", "email",
                            "telefono", "cellulare", "interessi", "indirizzo",
                            "riferimenti" },
                    new int[] { R.id.tvNomeCognome, R.id.tvDataDiNascita,
                            R.id.tvTipologiaUtente, R.id.tvAziendaCollegata,
                            R.id.tvEmail, R.id.tvTelefono, R.id.tvCellulare,
                            R.id.tvInteressi, R.id.tvIndirizzo, R.id.tvRiferimenti });

            setListAdapter(adapter);

            final ListView lv = getListView();
            lv.setTextFilterEnabled(true);
            lv.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    @SuppressWarnings("unchecked")
                    HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
                    Toast.makeText(getApplicationContext(), "ID '" + o.get("idAnagrafica") + "' was clicked.",
                            Toast.LENGTH_LONG).show();

                }
            });

            progressDialog.dismiss();
        }
    }


    public class PhoneCallListener extends PhoneStateListener {

        private boolean isPhoneCalling = false;

        String LOG_TAG = "LOGGING 123";

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {

            if (TelephonyManager.CALL_STATE_RINGING == state) {
                // phone ringing
                Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
            }

            if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
                // active
                Log.i(LOG_TAG, "OFFHOOK");

                isPhoneCalling = true;
            }

            if (TelephonyManager.CALL_STATE_IDLE == state) {
                // run when class initial and phone call ended, need detect flag
                // from CALL_STATE_OFFHOOK
                Log.i(LOG_TAG, "IDLE");

                if (isPhoneCalling) {

                    Log.i(LOG_TAG, "restart app");

                    // restart app
                    Intent i = getBaseContext().getPackageManager()
                            .getLaunchIntentForPackage(
                                    getBaseContext().getPackageName());
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);

                    isPhoneCalling = false;
                }

            }
        }
    }
}

here’s the detail xml code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/tvNomeCognome"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:drawableLeft="@drawable/icon"
                android:drawablePadding="10dp"
                android:padding="7dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textSize="24dp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:padding="4dp" >

            <TextView
                android:id="@+id/tvTipologiaUtente"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="2dp"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/tvDataDiNascita"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="2dp"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/tvEmail"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:autoLink="email"
                android:linksClickable="true"
                android:padding="2dp"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/tvTelefono"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:autoLink="phone"
                android:linksClickable="true"
                android:padding="2dp"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/tvCellulare"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:autoLink="phone"
                android:linksClickable="true"
                android:padding="2dp"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/tvInteressi"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="2dp"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/tvAziendaCollegata"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="2dp"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/tvIndirizzo"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="2dp"
                android:textSize="18dp" />

            <TextView
                android:id="@+id/tvRiferimenti"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:padding="2dp"
                android:textSize="18dp" />

            <Button
                android:id="@+id/bCall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/chiama" />
        </LinearLayout>
    </LinearLayout>

</ScrollView>
  • 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-03T05:06:08+00:00Added an answer on June 3, 2026 at 5:06 am

    That button might not be part of the ListView, just of the main layout of that Activity.

    If I understand what you’re saying, you have a main view containing a ListView and a Button. If that affirmation is right, then you need to use an Activity instead of ListActivity or use :

    mActivity= this ;
    Button button = new Button(this);
    button.setText("push me");
    button.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    button.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
                Toast.makeText(mActivity, "push", Toast.LENGTH_SHORT).show();
            }
        });
    getListView().addFooterView(button);
    

    Be sure to call addFooterView(View v) before setAdapter(ListAdapter adapter)

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

Sidebar

Related Questions

I need to be able to make a program that looks through a mailbox
Here is the situation: I have a huge data set that I need quick
I have team members that need to be able to checkin VBA modules/classes created
I have a python program that calls a stored procedure from db2 database. I
I have a activity displaying call logs in a ListView. The adapter used here
I need to be able to make a tree like structure in the appengine
I need to be able to make retries in node.js in the event of
I need to be able to be able to make some text on terminal
In my current project (presentation, slide software) I need to be able to make
Team: I need to invoke a WF activity (XAML) from a WF service (XAMLX)

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.