1

次の問題について助けてください: sqlite のリストを持っているように見える AlertDialog があり、このリストをロードするためにレイアウト xml を実行し、レイアウトにはゴミ箱付きの ImageView が含まれています。コード public void deleteClick (View v) {ここで、除外の確信があるかどうかを尋ねる別の AlertDialog が表示されます。しかし、クリックされたゴミ箱の位置を取得できません。

以下は、コードの一部です。

public void FavClick(View v) {

    SQLiteDatabase db = openOrCreateDatabase("rmtc.db", Context.MODE_PRIVATE, null);

    Cursor cursor = db.rawQuery("SELECT * FROM favpontos ORDER BY apelido ASC", null);

    String[] from = {"apelido", "ponto"};
    int[] to = {R.id.txvApelido, R.id.txvPonto};

    final SimpleCursorAdapter ad = new SimpleCursorAdapter(getBaseContext(), R.layout.favoritos, cursor, from, to);




    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    builder.setTitle("Pontos favoritos");
    builder.setIcon(R.drawable.ic_logo_white);
    builder.setAdapter(ad, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
             // Do something with the selection


            int posicao = (int) ad.getItemId(id);

            SQLiteDatabase banco = openOrCreateDatabase("rmtc.db", Context.MODE_PRIVATE, null);
            Cursor c = banco.rawQuery("SELECT * FROM favpontos WHERE _id = "+ posicao, null);

            while(c.moveToNext()){

                EditText txtPonto = (EditText)findViewById(R.id.txtPonto);
                txtPonto.setText(c.getString(c.getColumnIndex("ponto")));

            }





        }

    });
    AlertDialog alert = builder.create();
    alert.show();




}

public void deleteClick(View v) {


    new AlertDialog.Builder(MainActivity.this)
    .setTitle("Deletar ponto favorito")
    .setMessage("Tem certeza que deseja deletar este ponto?")
    .setIcon(R.drawable.ic_logo_white)
    .setPositiveButton("Deletar", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {
            // TODO Auto-generated method stub



            Toast.makeText(getBaseContext(), "( " +POSITION????+ " )", Toast.LENGTH_LONG).show();
        }


        })


    .setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

        }


    })


    .show();    



} 

および xml レイアウト:favoritos.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/ic_menu_delete"
        android:onClick="deleteClick" />

    <TextView
        android:id="@+id/txvApelido"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@+id/imageView1"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/txvPonto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/txvApelido"
        android:layout_toLeftOf="@+id/imageView1"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>

ありがとう!

英語を許してください、私はブラジル出身です

4

0 に答える 0