ClickListener не работает в cursorAdapter [duplicate]

Попробуйте

<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";

$message = "
    <html>
    <head>
       <title>HTML email</title>
    </head>
    <body>
      <p>This email contains HTML Tags!</p>
      <table>
        <tr>
         <th>Firstname</th>
         <th>Lastname</th>
        </tr>
        <tr>
          <td>John</td>
          <td>Doe</td>
        </tr>
      </table>
    </body>
    </html>";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";

mail($to,$subject,$message,$headers);
?> 
1
задан Wilder Pereira 14 April 2016 в 11:18
поделиться

1 ответ

Одним из решений является создание CustomAdapter, который расширяет SimpleCursorAdapter. Затем переопределите метод bindView В bindView найдите Button, затем обработайте onClickEvent

public class CustomAdapter extends SimpleCursorAdapter {

    private Context mContext;
    private Context appContext;
    private int layout;
    private Cursor cr;
    private final LayoutInflater inflater;

    public CustomAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
        super(context, layout, c, from, to);
        this.layout = layout;
        this.mContext = context;
        this.inflater = LayoutInflater.from(context);
        this.cr = c;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return inflater.inflate(layout, null);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        super.bindView(view, context, cursor);
        ...
        TextView tv_Name = (TextView) view.findViewById(R.id.tv_Name);
        tv_Name.setText(...);
        ...
        Button btnRemove = (Button) view.findViewById(R.id.btn_remove);
        btnRemove.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // button click
                // Remove your item here 

            }
        });
    }
}

Используйте его в Activity на

 final CustomAdapter sc = new CustomAdapter(this,R.layout.list_row2,ictemp, from, to, 0);
 lv.setAdapter(sc)

Надейтесь, что это помогает

1
ответ дан John Joe 21 August 2018 в 21:15
поделиться
  • 1
    спасибо за ответ, но как я могу получить позицию кнопки в списке? – smart_coder 14 April 2016 в 11:17
  • 2
    отлично работает :) также я нашел, как получить позицию thanksss alot – smart_coder 14 April 2016 в 11:38
Другие вопросы по тегам:

Похожие вопросы: