Skip to content

Instantly share code, notes, and snippets.

@yudanta
Created June 8, 2015 17:56
Show Gist options
  • Save yudanta/4b5b7b0d42afe2610123 to your computer and use it in GitHub Desktop.
Save yudanta/4b5b7b0d42afe2610123 to your computer and use it in GitHub Desktop.
DataAdapter
package co.nuwira.nwrandroiddev;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Amanda on 6/8/15.
*/
public class DataAdapter extends ArrayAdapter<Shelter> {
private final Context context;
List<Shelter> items;
int txtViewResId;
public DataAdapter(Context context, int txtViewResId, ArrayList<Shelter> items){
super(context, txtViewResId, items);
this.txtViewResId = txtViewResId;
this.items = items;
this.context = context;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(txtViewResId, parent, false);
TextView name = (TextView) rowView.findViewById(R.id.name);
TextView desc = (TextView) rowView.findViewById(R.id.desc);
name.setText(items.get(position).getName());
desc.setText(items.get(position).getDescription());
rowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(context, "item clicked at pos: " + Integer.toString(position), Toast.LENGTH_SHORT).show();
Intent intentDetail = new Intent(context, DetailActivity.class);
Bundle extras = new Bundle();
extras.putInt("id", items.get(position).getIdShelter());
extras.putString("name", items.get(position).getName());
extras.putString("description", items.get(position).getDescription());
extras.putDouble("latitude", items.get(position).getLatitude());
extras.putDouble("longitude", items.get(position).getLongitude());
intentDetail.putExtras(extras);
context.startActivity(intentDetail);
}
});
return rowView;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment