user1207576
user1207576

Reputation: 17

Making a call using values from a Textview

I'm try to make a user make a phone call using values from a textview. the problem is that startActivity is undefined for the type View.onClicklistener. I'm trying to implement this in the lazyadapter get view class could someone please help me. Here is the code

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    final ViewHolder holder;
    if (convertView == null) {
        vi = inflater.inflate(R.layout.item, null);
        holder = new ViewHolder();
        holder.text3=(TextView) vi.findViewById(R.id.text3);
        holder.text = (TextView) vi.findViewById(R.id.text);
        holder.text2 = (TextView) vi.findViewById(R.id.text2);
        holder.image=(ImageView)vi.findViewById(R.id.image);



        vi.setTag(holder);

    } else
        holder = (ViewHolder) vi.getTag();

    holder.text.setText(list.get(position).Name);
    holder.text3.setText(list.get(position).phone);

    StringBuilder sb = new StringBuilder();
    sb.append(", Address: " + list.get(position).address);

    holder.text3.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
      String phonee="tel:"+ holder.text3.getText().toString().trim();
      Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(phonee));
        startActivity(intent);//error is here

        }
    });

    holder.text2.setText(sb.toString());
    holder.image.setTag(data[position]);
    imageLoader.DisplayImage(data[position], activity, holder.image);
    return vi;
}

Upvotes: 0

Views: 568

Answers (2)

asenovm
asenovm

Reputation: 6517

You can try the following code instead

v.getContext().startActivity(intent);

Upvotes: 0

Never Quit
Never Quit

Reputation: 2082

Try this, It works perfect to me..

Intent intent = new Intent(Intent.ACTION_CALL); 
            intent.setData(Uri.fromParts("tel", NUMBER, NUMBER));// Number is string variable..
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            MyActivity.this.startActivity(intent);

And Did you give PHONE permission to your app?

You need to provide that into your AndroidManifest.xml

It is

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="aexp.explistemptygroup">
  <uses-permission android:name="android.permission.CALL_PHONE" /> 
 <application>

Hope this will help you. Thanks....

Upvotes: 1

Related Questions