Reputation: 43
I have used LazyAdapter for creating a custom listview. Now I require to use an image which can be clicked to dial a number. The error is coming in the onclick method of the image. StartActivity says "there is no such method in LazyAdapter". I am posting the code below.
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private String[] data;
private String[] project;
Context con;
public LazyAdapter(Context con) {
this.con = con;
}
public LazyAdapter(Activity a, String[] pic, String[] p) {
activity = a;
data = pic;
project = p;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) con
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.item_result_page, null);
------more code----
ImageView ivCall = (ImageView) vi.findViewById(R.id.imageViewIRCall);
ivCall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String uri = "tel:9818222333";
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(uri));
startActivity(intent);
}
});
return vi;
}
I have already refered this link but the error is there in startActivity. SO link
Upvotes: 0
Views: 314
Reputation: 1235
use
activity.startActivity(intent);
instead of
startActivity(intent);
and make sure you have permission for phone call in the AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE"/>
Upvotes: 1
Reputation: 10969
Simply you need to append context of activity while calling intent!
Within Onclick@
Use#
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(uri));
activity.startActivity(intent);
Instead#
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(uri));
startActivity(intent);
Additionally#
Use ViewHoder inside getView()
method and set tag to button and get tag
inside onClick to get correct position of view.
Upvotes: 0