Calling ACTION_CALL intent from arraylist

gojic

New Member
#1
I created araylist and stored list of some most important services in small town ,and some random img of phone.The idea was that when user press it it would via intent call that number.But the problem is i don't know where to store phone numbers.I have vague idea how to call that intent but it's all fell apart because i have no idea from where to call phone numbers,where to store it....All phone numbers are different so that add to complexity...

JAVA code
Mã:
package com.example.korisnik.indjijavodic;

    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.widget.ListView;

    import java.util.ArrayList;

    public class Dobrodosli extends AppCompatActivity {
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.lista);

            ArrayList<AndroidDobrodosli> androidDobrodosli = new ArrayList<>();
            androidDobrodosli.add(new AndroidDobrodosli("Taksi stanica"));
            androidDobrodosli.add(new AndroidDobrodosli("Autobuska stanica"));
            androidDobrodosli.add(new AndroidDobrodosli("Zeleznicka stanica"));
            androidDobrodosli.add(new AndroidDobrodosli("Turisticka agencija grada"));
            androidDobrodosli.add(new AndroidDobrodosli("Policija"));
            androidDobrodosli.add(new AndroidDobrodosli("Hitna pomoc"));

            DobrodosliAdapter dobrodosliAdapter = new DobrodosliAdapter(this,androidDobrodosli);
            ListView listView = findViewById(R.id.lista_brojeva);
            listView.setAdapter(dobrodosliAdapter);

        }
    }



     public class AndroidDobrodosli {
        private String mInfo;

        public int getmBrTelefona() {
            return mBrTelefona;
        }

        private int mBrTelefona;
        public String getmInfo() {
            return mInfo;
        }


        public AndroidDobrodosli(String mInfo,int mBrTelefona) {
            this.mInfo = mInfo;
            this.mBrTelefona = mBrTelefona;
        }
    }

    public class DobrodosliAdapter extends ArrayAdapter<AndroidDobrodosli> {


    public DobrodosliAdapter(Dobrodosli dobrodosli, ArrayList<AndroidDobrodosli> androidDobrodosli) {
        super(dobrodosli, 0, androidDobrodosli);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View listView = convertView;
        if (listView == null) {
            listView = LayoutInflater.from(getContext()).inflate(R.layout.dobrodosli, parent, false);
        }

        AndroidDobrodosli dobrodosli = getItem(position);
        TextView brojTelefona = (TextView) listView.findViewById(R.id.broj_telefona);
        brojTelefona.setText(dobrodosli.getmInfo());
        return listView;
    }
}
And please don't tell me about SQL and storing information...it's still beyond me
 

Admin

Administrator
Thành viên BQT
#2
Using your code...

When setting up your arrayList change your adds to something like this to include the number..

Mã:
androidDobrodosli.add(new AndroidDobrodosli("Taksi stanica","01234567890"));
When you set up your onClick you will have the postion so you can do something like this to setup the intent...
Mã:
Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse("tel:"+androidDobrodsli.get(position).getmBrTelefona()); startActivity(intent);
 
Top