I have a list view that is inflated from my adapter.
When I click on one of the Buttons I get the wrong item.
It used to work o.k until I added the whatsApp
button.
This is my adapter:
public class shawarmaddapter extends ArrayAdapter<shawarma> {
String nname;
double lat,lon;
public shawarmaddapter(Context context, List<shawarma> resource) {
super(context,0, resource);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
....
if (convertView==null)
{
convertView= LayoutInflater.from(getContext()).inflate(R.layout.shawarmaddapter,parent,false);
}
....
waze= (ImageButton)convertView.findViewById(R.id.adapterWazeBTN);
whats = (ImageButton)convertView.findViewById(R.id.whats);
locName=name.getText().toString();
....
nname = sh1.getName();
name.setText(sh1.getName());
....
if (sh1.getParking()==1)
park.setChecked(true);
else
park.setChecked(false);
rate.setRating((float) sh1.getRank());
rate.setIsIndicator(true);
listener lis = new listener();
waze.setOnClickListener(lis);
whats.setOnClickListener(lis);
lat= sh1.getLat();
lon= sh1.getLon();
return convertView;
}
there is a onClickListener added in the code thats supposed to check the location if waze button is pressed or the name if whatsapp button is pressed. This is the code
class listener implements View.OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.adapterWazeBTN:
Log.i("a7", "button clicked");
// Log.i("a7", lat+" lat, "+lon+" lon"+ "distance: "+ sh1.getDistance());
try
{
String url = "waze://?ll="+lat+","+lon+"&navigate=yes";
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( url ) );
shawarmaList.con. startActivity( intent );
}
catch ( ActivityNotFoundException ex )
{
Intent intent =
new Intent( Intent.ACTION_VIEW, Uri.parse( "market://details?id=com.waze" ) );
shawarmaList.con.startActivity(intent);
}
catch (Exception ex)
{
Log.i("a7",ex.toString());
}
break;
case R.id.whats:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "do you want to Join me to "+nname+"?");
sendIntent.setType("text/plain");
try {
Toast.makeText(shawarmaList.con.getApplicationContext(),nname,Toast.LENGTH_SHORT).show();
shawarmaList.con.startActivity(sendIntent);
} catch (Exception e) {
Log.i("a7",e.getMessage());
}
break;
}
}
}
How can I change this to get the right item?