Custom events in android
<p>I have a working android app. In this app I have an activity which displays transactions from SqlServer in a ListView, I've used ListViewAdapter (extends BaseAdapter) and net.sourceforge.jtds.jdbc.Driver to display these Transactions, now I have added a Button to each row in the ListView and I want to delete the transaction from the server whenever user taps on the Button. I don't know where to start.</p>

<p>TransactionActivity.java</p>

<pre><code>public class TransactionActivity extends AppCompatActivity implements   OnClickListener {

private EditText tranDate;
private DatePickerDialog dtpDialog;
private SimpleDateFormat dateFormat;
private ListView lvTransactions;
private Button btnAddNewTransaction;
private TransactionsListViewAdapter adapter;
private ArrayList&lt;HashMap&lt;String, String&gt;&gt; transactionsList;
private Date selectedDate;
private SqlDatabaseHelper sqldb = new SqlDatabaseHelper(this);
private DecimalFormat df = new DecimalFormat("#.00");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transaction);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH);

    tranDate = (EditText) findViewById(R.id.tranDate);
    tranDate.setInputType(InputType.TYPE_NULL);
    tranDate.requestFocus();

    setDateTimeField();

    lvTransactions = (ListView) findViewById(R.id.lvTransactions);
    transactionsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();

    tranDate.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            refreshTransactions();
        }
    });
}

private void refreshTransactions() {
    transactionsList.clear();
    HashMap&lt;String, String&gt; headerRow = new HashMap&lt;String, String&gt;();
    headerRow.put(FIRST_COLUMN, "Party");
    headerRow.put(SECOND_COLUMN, "Type");
    headerRow.put(THIRD_COLUMN, "Amount");
    headerRow.put(FOURTH_COLUMN, "Status");
    transactionsList.add(headerRow);
    List&lt;Transaction&gt; tranList = sqldb.getTransactionsByDate(selectedDate);
    for (Transaction t : tranList) {
        HashMap&lt;String, String&gt; tranRow = new HashMap&lt;String, String&gt;();
        tranRow.put(FIRST_COLUMN, t.get_party().getName());
        String tTypeStr;
        int tType = t.get_transactionType();
        switch (tType) {
            case 0:
                tTypeStr = "आया";
                break;
            case 1:
                tTypeStr = "दिया";
                break;
            case 2:
                tTypeStr = "जमा";
                break;
            case 3:
                tTypeStr = "नामे";
                break;
            default:
                tTypeStr = "";
        }
        int tStat = t.get_transactionStatus();
        String tStatStr = "";
        switch (tStat) {
            case 0:
                tStatStr = "Fresh";
                break;
            case 1:
                tStatStr = "Synced";
                break;
            case 2:
                tStatStr = "Deleted";
                break;
        }
        tranRow.put(SECOND_COLUMN, tTypeStr);
        tranRow.put(THIRD_COLUMN, df.format(t.get_amount()));
        tranRow.put(FOURTH_COLUMN, tStatStr);
        transactionsList.add(tranRow);
    }
    adapter = new TransactionsListViewAdapter(this, transactionsList);
    lvTransactions.setAdapter(adapter);
    lvTransactions.invalidateViews();
}

private void setDateTimeField() {
    tranDate.setOnClickListener(this);

    Calendar calendar = Calendar.getInstance();
    dtpDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Calendar newDate = Calendar.getInstance();
            newDate.set(year, monthOfYear, dayOfMonth);
            selectedDate = newDate.getTime();
            tranDate.setText(dateFormat.format(newDate.getTime()));
        }
    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
}


@Override
public void onClick(View view) {
    if (view == tranDate) {
        dtpDialog.show();
    }
}
</code></pre>

<p>}</p>

<p>TransactionListViewAdapter.java</p>

<pre><code>public class TransactionsListViewAdapter extends BaseAdapter {
public ArrayList&lt;HashMap&lt;String, String&gt;&gt; list;
Activity activity;
TextView txtFirst;
TextView txtSecond;
TextView txtThird;
TextView txtFourth;
Button btnDeleteTran;


public TransactionsListViewAdapter(Activity activity, ArrayList&lt;HashMap&lt;String, String&gt;&gt; list) {
    super();
    this.activity = activity;
    this.list = list;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return list.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return list.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub


    LayoutInflater inflater = activity.getLayoutInflater();
    View view = null;
    convertView = null;
    if (convertView == null) {

        convertView = inflater.inflate(R.layout.transaction_list_layout, null);

        txtFirst = (TextView) convertView.findViewById(R.id.txtTranParty);
        txtSecond = (TextView) convertView.findViewById(R.id.txtTranType);
        txtThird = (TextView) convertView.findViewById(R.id.txtTranAmount);
        txtFourth = (TextView) convertView.findViewById(R.id.txtTranStatus);
        btnDeleteTran = (Button) convertView.findViewById(R.id.btnTranDelete);


        convertView.setTag(R.id.txtTranParty, txtFirst);
        convertView.setTag(R.id.txtTranType, txtSecond);
        convertView.setTag(R.id.txtTranAmount, txtThird);
        convertView.setTag(R.id.txtTranStatus, txtFourth);
        convertView.setTag(R.id.btnTranDelete, btnDeleteTran);

    }/* else {
        txtFirst = (TextView) convertView.getTag(R.id.Party);
        txtSecond = (TextView) convertView.getTag(R.id.Opponent1);
        txtThird = (TextView) convertView.getTag(R.id.Opponent2);
        txtFourth = (TextView) convertView.getTag(R.id.Draw);
    }*/

    HashMap&lt;String, String&gt; map = list.get(position);
    txtFirst.setText(map.get(FIRST_COLUMN));
    txtSecond.setText(map.get(SECOND_COLUMN));
    txtThird.setText(map.get(THIRD_COLUMN));
    txtFourth.setText(map.get(FOURTH_COLUMN));

    if (txtFirst.getText().equals("Party")) {
        btnDeleteTran.setVisibility(View.INVISIBLE);
    }

    btnDeleteTran.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });
    return convertView;
}
</code></pre>

<p>}</p>