i am trying to add a phone button to a city guide app, where there should be a phone icon in each item that when clicked will redirect me to the dialer app with the phone number already be written.
this is the main activity code
public class Resto extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resto);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ListView lv;
lv=(ListView) findViewById(R.id.listview);
String[] names= {"L'olivo verde","Lounge36","Punto Alto","Sa7se7", "Maison Jabbour", "Pizza Napoli", "Capri","Classic burger joint","kaakunada","Ichiban Express","Ikura Sushi","Machos" };
int[] imageids = {R.drawable.lolivo,R.drawable.lounge,R.drawable.punto,R.drawable.sahseh, R.drawable.jabbour, R.drawable.napoli, R.drawable.capri,R.drawable.cbj, R.drawable.kaak, R.drawable.ichiban, R.drawable.ikura,R.drawable.machos, R.drawable.gate};
lv.setAdapter(new CustomAdapter(this,names,imageids));
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
and this is the customAdapter code
public class CustomAdapter extends BaseAdapter{
String[] result;
Context context;
int[] image ID;
LayoutInflater inflater=null;
public CustomAdapter(Context c, String[] names, int[] imageids)
{
result = names;
context= c;
imageID = imageids;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return result.length;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
public class Holder {
TextView tv;
ImageView img;
}
public View getView(int i, View view, ViewGroup viewGroup) {
// i is the position. starts at 0 and keeps on incremeting till the end of the data
Holder holder= new Holder();
final View rowView;
rowView = inflater.inflate(R.layout.restos,null);
holder.tv = (TextView) rowView.findViewById(R.id.textView);
holder.img= (ImageView) rowView.findViewById(R.id.imageView);
holder.img = (ImageView) view.findViewById(R.id.imageclick);
holder.tv.setText(result[i]);
holder.img.setImageResource(imageID[i]);
rowView.setTag(i);
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, "position " + rowView.getTag(), Toast.LENGTH_LONG).show();
}
});
return rowView;
}
}