I'm trying to delete items on a list view using the daimajia swipe layout, so when i swipe a button appears, but how do i know which delete button from the items was pressed? is there a listener that i can set on my list view adapter?
here is my code:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_row_route); ArrayList<String> myTripOrigin = new ArrayList<>(); ArrayList<String> myTripDestiny = new ArrayList<>(); ArrayList<String> myTripHour = new ArrayList<>(); ArrayList<Boolean> myTripBools = new ArrayList<Boolean>(); ArrayList <boolean[]> myTripSchedule = new ArrayList<>(); ListAdapter userAdapter = new CustomAdapterRoute(getApplicationContext(), myTripOrigin,myTripDestiny,myTripHour,myTripSchedule,myTripBools); ListView userListView = (ListView) findViewById(R.id.listViewRoute); int padding = 50; userListView.setPadding(padding, padding, padding, padding); userListView.setAdapter(userAdapter); } }
and also this is my adapter code: public class CustomAdapterRoute extends ArrayAdapter{
private ArrayList<String> itemFrom = new ArrayList<>(); private ArrayList<String> itemTo = new ArrayList<>(); private ArrayList<String> itemHour = new ArrayList<>(); private ArrayList<boolean[]> itemSchedule = new ArrayList<>(); private ArrayList<Boolean> itemRole = new ArrayList<>(); //Send arrays public CustomAdapterRoute(Context context, ArrayList<String> stringArray, ArrayList<String> stringTo, ArrayList<String> stringHour, ArrayList<boolean[]> stringSchedule,ArrayList<Boolean> boolRole){ super(context, R.layout.custom_row_route,stringArray); //save the arrays in global var this.itemFrom = stringArray; this.itemTo = stringTo; this.itemHour = stringHour; this.itemSchedule = stringSchedule; this.itemRole = boolRole; } @Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater customInflater = LayoutInflater.from(getContext()); final View customView = customInflater.inflate(R.layout.custom_row_route, parent, false); String singleFrom = itemFrom.get(position); String singleTo = itemTo.get(position); String singleHour = itemHour.get(position); boolean singleRole = itemRole.get(position); //Get TextView from the custom row TextView customText = (TextView) customView.findViewById(R.id.fromText); TextView customTextTo = (TextView) customView.findViewById(R.id.toText); TextView customTextHour = (TextView) customView.findViewById(R.id.hourText); ImageView RoleImage = (ImageView) customView.findViewById(R.id.ImageRole); RoleImage.setImageResource(singleRole ? R.mipmap.steer3 : R.mipmap.hand3); //TextView customTextSchedule = (TextView) customView.findViewById(R.id.repeatText); //Give values from each position of the array customText.setText(singleFrom); customTextTo.setText(singleTo); customTextHour.setText(singleHour); return customView; }
thanks for your help!
No comments:
Post a Comment