Android 显示来自sql数据库的ListView/ListAdapter的单个记录

Android 显示来自sql数据库的ListView/ListAdapter的单个记录,android,sqlite,csv,android-listview,simplecursoradapter,Android,Sqlite,Csv,Android Listview,Simplecursoradapter,我做了一点旅行,我想创建一个应用程序,让我可以将出租车预订保存到数据库中。我只添加了几个字段来了解这一切是如何工作的。我对编程非常陌生,并遵循一些教程创建了一个应用程序,允许我获取csv文件并将其上载到应用程序数据库。这很好,我在显示数据方面没有问题 我设法让它同时使用Toast和alert来打开包含数据的窗口,但只有6个字段。。。我需要全部16个显示… 我已经在这方面取得了一些进展,但当我单击列表项时,仍然存在应用程序终止问题 我曾试图通过newintent在TaxiDetails中调用new

我做了一点旅行,我想创建一个应用程序,让我可以将出租车预订保存到数据库中。我只添加了几个字段来了解这一切是如何工作的。我对编程非常陌生,并遵循一些教程创建了一个应用程序,允许我获取csv文件并将其上载到应用程序数据库。这很好,我在显示数据方面没有问题

我设法让它同时使用Toast和alert来打开包含数据的窗口,但只有6个字段。。。我需要全部16个显示…
我已经在这方面取得了一些进展,但当我单击列表项时,仍然存在应用程序终止问题

我曾试图通过newintent在TaxiDetails中调用newview结果表。没有快乐。。。谢谢你的帮助。 代码如下-感谢所有帮助并提前感谢

MainActivity.java

package com.stravides.jdw;

import android.app.AlertDialog;
import android.content.Context;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.ActivityNotFoundException;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class MainActivity extends ListActivity {
    TextView lbl;
    DBController controller = new DBController(this);
    Button btnimport;
    Button btnphone;
    Button btnclear;

    ListView lv;
    ArrayList<HashMap<String, String>> myList;
    public static final int requestcode = 1;
    final Context context = this;

    protected Cursor kursor;
    protected ListAdapter adapter;
    protected SQLiteDatabase db;

    public AdapterView.OnItemClickListener mMessageClickedHandler = new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            Intent intent = new Intent("com.stravides.jdw.TaxiDetails.class");
            Cursor kursor = (Cursor) adapter.getItem(position);
            intent.putExtra("TAXI_ID", kursor.getInt(kursor.getColumnIndex("_id")));
            startActivity(intent);
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        lbl = (TextView) findViewById(R.id.txtresulttext);
        btnimport = (Button) findViewById(R.id.btnupload);
        btnphone =  (Button) findViewById(R.id.btnphone);
        btnclear =  (Button) findViewById(R.id.btnclear);
        lv = getListView();


        btnimport.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT);
                fileintent.setType("gagt/sdf");
                try {
                    startActivityForResult(fileintent, requestcode);
                } catch (ActivityNotFoundException e) {
                    lbl.setText("No activity that can handle file selection. Showing alternatives.");
                }

            }
        });

        btnclear.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SQLiteDatabase db = controller.getWritableDatabase();
                    String tableName = "taxiinfo";
                    db.execSQL("delete from " + tableName);
                    myList = controller.getAllProducts();
                    if (myList.size() == 0) {
                        ListView lv = getListView();
                        ListAdapter adapter = new SimpleAdapter(MainActivity.this, myList,R.layout.v, new String[]
                                {"bID", "bDate", "bTime", "bFrom", "bTo","bFlightNum", "bFlightDest", "bPassenger", "bEmail", "bTelno", "bMobNo", "bCostCentre", "bPersNo", "bCombine", "bNumPass", "bRemarks"}, new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});
                        setListAdapter(adapter);
                        lbl.setText("Data Cleared");
                    }
                }
            });

        btnphone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String uri = "tel:" + "0031251491418";
                Intent intent = new Intent(Intent.ACTION_DIAL);
                intent.setData(Uri.parse(uri));
                startActivity(intent);
            }
        });

            myList= controller.getAllProducts();
            if (myList.size() != 0) {
                ListView lv = getListView();
                ListAdapter adapter = new SimpleAdapter(MainActivity.this, myList,
                        R.layout.v, new String[]{"bID", "bDate", "bTime", "bFrom", "bTo","bFlightNum", "bFlightDest", "bPassenger", "bEmail", "bTelno", "bMobNo", "bCostCentre", "bPersNo", "bCombine", "bNumPass", "bRemarks"}, new int[]{
                        R.id.txttaxibID, R.id.txttaxibDate, R.id.txttaxibTime,R.id.txttaxibFrom, R.id.txttaxibTo, R.id.txttaxibFlightNum, R.id.txttaxibFlightDest, R.id.txttaxibPassenger, R.id.txttaxibEmail, R.id.txttaxibTelno, R.id.txttaxibMobNo, R.id.txttaxibCostCentre, R.id.txttaxibPersNo, R.id.txttaxibCombine, R.id.txttaxibNumPass, R.id.txttaxibRemarks});
                setListAdapter(adapter);
                lbl.setText("");
            }

            lv.setOnItemClickListener(mMessageClickedHandler);
        }


    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data == null)
            return;
        switch (requestCode) {
            case requestcode:
                String filepath = data.getData().getPath();
                controller = new DBController(getApplicationContext());
                SQLiteDatabase db = controller.getWritableDatabase();
                String tableName = "taxiinfo";
                db.execSQL("delete from " + tableName);
                try {
                    if (resultCode == RESULT_OK) {
                        try {
                            FileReader file = new FileReader(filepath);
                            BufferedReader buffer = new BufferedReader(file);
                            ContentValues contentValues = new ContentValues();
                            String line = "";
                            db.beginTransaction();
                            while ((line = buffer.readLine()) != null) {
                                String[] str = line.split(",", 16);
                                String bID = str[0];
                                String bDate = str[1];
                                String bTime = str[2];
                                String bFrom = str[3];
                                String bTo = str[4];
                                String bFlightNum = str[5];
                                String bFlightDest = str[6];
                                String bPassenger = str[7];
                                String bEmail = str[8];
                                String bTelno = str[9];
                                String bMobNo = str[10];
                                String bCostCentre = str[11];
                                String bPersNo = str[12];
                                String bCombine = str[13];
                                String bNumPass = str[14];
                                String bRemarks = str[15];
                                contentValues.put("bID", bID);
                                contentValues.put("bDate", bDate);
                                contentValues.put("bTime", bTime);
                                contentValues.put("bFrom", bFrom);
                                contentValues.put("bTo", bTo);
                                contentValues.put("bFlightNum", bFlightNum);
                                contentValues.put("bFlightDest", bFlightDest);
                                contentValues.put("bPassenger", bPassenger);
                                contentValues.put("bEmail", bEmail);
                                contentValues.put("bTelno", bTelno);
                                contentValues.put("bMobNo", bMobNo);
                                contentValues.put("bCostCentre", bCostCentre);
                                contentValues.put("bPersNo", bPersNo);
                                contentValues.put("bCombine", bCombine);
                                contentValues.put("bNumPass", bNumPass);
                                contentValues.put("bRemarks", bRemarks);
                                db.insert(tableName, null, contentValues);
                                lbl.setText("Successfully Updated Database.");
                            }
                            db.setTransactionSuccessful();
                            db.endTransaction();
                        } catch (IOException e) {
                            if (db.inTransaction())
                                db.endTransaction();
                            Dialog d = new Dialog(this);
                            d.setTitle(e.getMessage().toString() + "first");
                            d.show();
                        }
                    } else {
                        if (db.inTransaction())
                            db.endTransaction();
                        Dialog d = new Dialog(this);
                        d.setTitle("Only CSV files allowed");
                        d.show();
                    }
                } catch (Exception ex) {
                    if (db.inTransaction())
                        db.endTransaction();
                    Dialog d = new Dialog(this);
                    d.setTitle(ex.getMessage().toString() + "second");
                    d.show();
                }
        }

        myList= controller.getAllProducts();
        if (myList.size() != 0) {
            ListView lv = getListView();
            ListAdapter adapter = new SimpleAdapter(MainActivity.this, myList,
                    R.layout.v, new String[]{"bID", "bDate", "bTime", "bFrom", "bTo","bFlightNum", "bFlightDest", "bPassenger", "bEmail", "bTelno", "bMobNo", "bCostCentre", "bPersNo", "bCombine", "bNumPass", "bRemarks"}, new int[]{
                    R.id.txttaxibID, R.id.txttaxibDate, R.id.txttaxibTime,R.id.txttaxibFrom, R.id.txttaxibTo, R.id.txttaxibFlightNum, R.id.txttaxibFlightDest, R.id.txttaxibPassenger, R.id.txttaxibEmail, R.id.txttaxibTelno, R.id.txttaxibMobNo, R.id.txttaxibCostCentre, R.id.txttaxibPersNo, R.id.txttaxibCombine, R.id.txttaxibNumPass, R.id.txttaxibRemarks});
        }
    }
}
package com.stravides.jdw;
        import android.content.Context;
        import android.database.Cursor;
        import android.database.sqlite.SQLiteDatabase;
        import android.database.sqlite.SQLiteOpenHelper;
        import android.util.Log;
        import java.util.ArrayList;
        import java.util.HashMap;

public class DBController extends SQLiteOpenHelper {
    private static final String LOGCAT = null;
    public DBController(Context applicationcontext) {
        super(applicationcontext, "jdwtaxi.db", null, 1);  // creating DATABASE
        Log.d(LOGCAT, "Created");
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
        String query;
        query = "CREATE TABLE IF NOT EXISTS taxiinfo ( Id INTEGER PRIMARY KEY, bID TEXT,bDate TEXT, bTime TEXT,bFrom TEXT, bTo TEXT, bFlightNum TEXT, bFlightDest TEXT, bPassenger TEXT, bEmail TEXT, bTelno TEXT, bMobNo TEXT, bCostCentre TEXT, bPersNo TEXT, bCombine TEXT, bNumPass TEXT, bRemarks TEXT)";
        database.execSQL(query);
    }


    @Override
    public void onUpgrade(SQLiteDatabase database, int version_old,int current_version) {
        String query;
        query = "DROP TABLE IF EXISTS taxiinfo";
        database.execSQL(query);
        onCreate(database);
    }


    public ArrayList<HashMap<String, String>> getAllProducts() {
        ArrayList<HashMap<String, String>> taxiList;
        taxiList = new ArrayList<HashMap<String, String>>();
        String selectQuery = "SELECT  * FROM taxiinfo";
        SQLiteDatabase database = this.getWritableDatabase();
        Cursor cursor = database.rawQuery(selectQuery, null);
        if (cursor.moveToFirst()) {
            do {
                //Id, Company,Name,Price
                HashMap<String, String> map = new HashMap<String, String>();
                map.put("Id", cursor.getString(0));
                map.put("bID", cursor.getString(1));
                map.put("bDate", cursor.getString(2));
                map.put("bTime", cursor.getString(3));
                map.put("bFrom", cursor.getString(4));
                map.put("bTo", cursor.getString(5));
                map.put("bFlightNum", cursor.getString(6));
                map.put("bFlightDest", cursor.getString(7));
                map.put("bPassenger", cursor.getString(8));
                map.put("bEmail", cursor.getString(9));
                map.put("bTelno", cursor.getString(10));
                map.put("bMobNo", cursor.getString(11));
                map.put("bCostCentre", cursor.getString(12));
                map.put("bPersNo", cursor.getString(13));
                map.put("bCombine", cursor.getString(14));
                map.put("bNumPass", cursor.getString(15));
                map.put("bRemarks", cursor.getString(16));
                taxiList.add(map);
            } while (cursor.moveToNext());
        }
        return taxiList;
    }

}
package com.stravides.jdw;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;

/**
 * Created by Ken on 09/08/2015.
 */
public class TaxiDetails extends Activity {

    protected TextView bID;
    protected TextView bDate;
    protected TextView bTime;
    protected TextView bFrom;
    protected TextView bTo;
    protected TextView bFlightNum;
    protected TextView bFlightDest;
    protected TextView bPassenger;
    protected TextView bEmail;
    protected TextView bTelno;
    protected TextView bMobNo;
    protected TextView bCostCentre;
    protected TextView bPersNo;
    protected TextView bCombine;
    protected TextView bNumPass;
    protected TextView bRemarks;
    protected int taxiPos;

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.resultstable);

            taxiPos = getIntent().getIntExtra("TAXI_ID", 0);
            SQLiteDatabase db = (new DBController(this)).getWritableDatabase();
            Cursor cursor = db.rawQuery("SELECT bID, bDate, bCombine FROM taxiinfo WHERE bID = ?", new String[]{""+taxiPos});

            if (cursor.getCount() == 1)
            {
                cursor.moveToFirst();

                bID = (TextView) findViewById(R.id.txttaxibID2);
                bID.setText(cursor.getString(cursor.getColumnIndex("bID")));

                bDate = (TextView) findViewById(R.id.txttaxibDate2);
                bDate.setText(cursor.getString(cursor.getColumnIndex("bDate")));

                bCombine = (TextView) findViewById(R.id.txttaxibCombine2);
                bCombine.setText(cursor.getString(cursor.getColumnIndex("bCombine")));

            }

        }

    }
活动\u main.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"
        android:weightSum="9"
        android:background="#FFC7C7C7"
        >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="Booking Details"
            android:id="@+id/textView"
            android:layout_gravity="center_horizontal"
            android:layout_weight="0.24" />
        <!--  divider -->

    <LinearLayout
        android:id="@+id/lvcontainer"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.5"
        android:layout_alignParentTop="true"
        android:orientation="horizontal"
        android:padding="1dp"
        android:background="#FFC7C7C7"
        android:weightSum="6">

        <TextView
            android:id="@+id/txttaxibID"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".8"
            android:gravity="left"
            android:text="Ref"
            android:textColor="#000000"
            android:textSize="13sp"
            android:clickable="false" />

        <TextView
            android:id="@+id/txttaxibDate"
            android:layout_width="15dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:padding="3dp"
            android:text="Date"
            android:textColor="#000000"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/txttaxibTime"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".8"
            android:gravity="left"
            android:text="Time"
            android:padding="3dp"
            android:textColor="#000000"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/txttaxibFrom"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:text="From"
            android:padding="3dp"
            android:textColor="#000000"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/txttaxibTo"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:text="To"
            android:padding="3dp"
            android:textColor="#000000"
            android:textSize="13sp" />
        <TextView
            android:id="@+id/txttaxibCombine"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:text="Combine"
            android:padding="1dp"
            android:textColor="#000000"
            android:textSize="13sp" />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@+id/lvcontainer"
        android:layout_weight="6.59"
        android:clickable="false"></ListView>

    <TextView
        android:id="@+id/txtresulttext"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginLeft="5dp"
        android:layout_below="@android:id/list"
        android:layout_marginTop="2dp"
        android:layout_weight="0.5"
        android:gravity="left"
        android:text=""
        android:textColor="#FFF55F54"
        android:textSize="10sp"
        android:textStyle="italic|bold"></TextView>



    <LinearLayout
        android:id="@+id/lvbottom"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:layout_weight="1"
        android:weightSum="1">

        <Button
            android:id="@+id/btnupload"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:gravity="center"
            android:text="UPLOAD"
            android:textColor="#ffffff"
            android:background="#1083f5"
            android:textSize="15sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/btnclear"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.33"
            android:gravity="center"
            android:text="CLEAR"
            android:textColor="#ffffff"
            android:background="#1003f5"
            android:textSize="15sp"
            android:textStyle="bold" />

        <Button
            android:id="@+id/btnphone"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.34"
            android:gravity="center"
            android:text="CALL JDW"
            android:textColor="#ffffff"
            android:background="#ffff0000"
            android:textSize="15sp"
            android:textStyle="bold" />


    </LinearLayout>

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

    <LinearLayout
        android:id="@+id/lvh"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:scrollbars="horizontal"
        android:background="#ffe6e6e6"
        android:weightSum="5"
        android:minHeight="30dp"
        android:measureWithLargestChild="false"
        android:longClickable="false">
        <TextView
            android:id="@+id/txttaxibID"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:text="Ref"
            android:textColor="#000000"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/txttaxibDate"
            android:layout_width="15dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:padding="3dp"
            android:text="Date"
            android:textColor="#000000"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/txttaxibTime"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:text="Time"
            android:padding="3dp"
            android:textColor="#000000"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/txttaxibFrom"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:text="From"
            android:padding="3dp"
            android:textColor="#000000"
            android:textSize="13sp" />

        <TextView
            android:id="@+id/txttaxibTo"
            android:layout_width="1dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="left"
            android:text="To"
            android:padding="3dp"
            android:textColor="#000000"
            android:textSize="13sp" />

    </LinearLayout>

</LinearLayout>
<TextLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <TextView
            android:id="@+id/status2"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:text="Booking Details"
            android:textColor="#890000"
            android:textSize="25sp"
            android:textStyle="bold"
           />

    <TextView
        android:id="@+id/txttaxibID2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:layout_marginLeft="20dip"
        />

    <TextView
        android:id="@+id/txttaxibDate2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:layout_marginLeft="20dip" />

    <TextView
        android:id="@+id/txttaxibCombine2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:layout_marginLeft="20dip" />

</TextLayout>

您需要在
列表视图
上设置一个
监听器
。下面是一个简单的教程,它是如何工作的-

学习拦截和处理事件后,可以开始考虑导航到详细信息活动,或打开详细信息对话框


我建议您阅读中的所有基本教程-您所需要的就在那里。

您需要在
列表视图上设置一个
OnItemClickListener
。下面是一个简单的教程,它是如何工作的-

学习拦截和处理事件后,可以开始考虑导航到详细信息活动,或打开详细信息对话框


我建议您阅读中的所有基本教程-您所需要的就是这些。

我会这样做:

public void onClickList(final ListView list) {
    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(final AdapterView<?> parent,
                                final View view, final int position, long id) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setCancelable(false);
            alert.setMessage("youre message");
            final AlertDialog.Builder ok = alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which){
                    //add your code here
                    dialog.dismiss();
                }
            });
            alert.show();
        }
    });
}
public void onClickList(最终列表视图列表){
list.setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(最终适配器视图父级,
最终视图、最终整型位置、长id){
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
警报。可设置可取消(错误);
setMessage(“youre message”);
final AlertDialog.Builder ok=alert.setPositiveButton(“ok”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
//在这里添加您的代码
dialog.dismise();
}
});
alert.show();
}
});
}

其中列表是您创建的ListView对象。您可以将ListView发送到此方法
onClickListener()
以管理弹出窗口。顺便说一句,您可以创建自己的xml布局来呈现自定义视图。

我可以这样做:

public void onClickList(final ListView list) {
    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(final AdapterView<?> parent,
                                final View view, final int position, long id) {
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setCancelable(false);
            alert.setMessage("youre message");
            final AlertDialog.Builder ok = alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which){
                    //add your code here
                    dialog.dismiss();
                }
            });
            alert.show();
        }
    });
}
public void onClickList(最终列表视图列表){
list.setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(最终适配器视图父级,
最终视图、最终整型位置、长id){
AlertDialog.Builder alert=新建AlertDialog.Builder(此);
警报。可设置可取消(错误);
setMessage(“youre message”);
final AlertDialog.Builder ok=alert.setPositiveButton(“ok”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
//在这里添加您的代码
dialog.dismise();
}
});
alert.show();
}
});
}

其中列表是您创建的ListView对象。您可以将ListView发送到此方法
onClickListener()
以管理弹出窗口。顺便说一下,您可以创建自己的xml布局来呈现自定义视图。

感谢您在上述方面的帮助-我现在设法解决了这个问题

问题是想通过点击的位置太难了

MainActivity.java需要以下内容

public AdapterView.OnItemClickListener mMessageClickedHandler = new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v, int position, long id) {
        Intent intent = new Intent(MainActivity.this,TaxiDetails.class);
        intent.putExtra("TAXI_ID", position);
        startActivity(intent);
    }
};
然后,TaxiDetails.java就可以在intent中获取额外的信息

   taxiPos = getIntent().getIntExtra("TAXI_ID", 0);
   taxiPos=taxiPos+1;
    SQLiteDatabase db = (new DBController(this)).getWritableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM taxiinfo WHERE Id = ?", new String[]{""+taxiPos});

    if (cursor.getCount() == 1)

感谢您在上述方面的帮助-我现在设法解决了这个问题

问题是想通过点击的位置太难了

MainActivity.java需要以下内容

public AdapterView.OnItemClickListener mMessageClickedHandler = new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView parent, View v, int position, long id) {
        Intent intent = new Intent(MainActivity.this,TaxiDetails.class);
        intent.putExtra("TAXI_ID", position);
        startActivity(intent);
    }
};
然后,TaxiDetails.java就可以在intent中获取额外的信息

   taxiPos = getIntent().getIntExtra("TAXI_ID", 0);
   taxiPos=taxiPos+1;
    SQLiteDatabase db = (new DBController(this)).getWritableDatabase();
    Cursor cursor = db.rawQuery("SELECT * FROM taxiinfo WHERE Id = ?", new String[]{""+taxiPos});

    if (cursor.getCount() == 1)

我尝试并成功地捕捉到了这一事件,并用6个字段祝酒。。。。我现在试图做的是通过我创建的意图打开第二个视图-不确定这是否是我应该做的。嗯,我相当肯定它不起作用;)你的意图代码是错误的。尝试使用
Intent Intent=new Intent(这个,textdealts.class)
。第一个参数是您当前的活动,第二个参数是您想要达到的活动类别。感谢您的回答,不幸的是,在本次修订之前,我做了,我得到了一个红色的下斜杠。我复制了以前用于员工详细信息的示例,但这是一个ListView,不是AdapterView。不知道为什么不工作/编译这是因为您在OnClickListener中进行了操作。在本例中,
引用监听器,监听器不能在此处作为参数传递。您需要使用
MainActivity获取封闭的活动实例。这
Ok现在至少是“编译”了-但是当我按下一条记录打开新活动时,仍然有一些错误-它只是崩溃了,我得到了“不幸的是,JDW Taxis已停止”错误。一定是别的原因造成的。将OnItemClickListener的行逐个注释掉它失败的一行是“'Cursor kursor=(Cursor)adapter.getItem(position);”“它无法设置适配器-一定是使用了错误的适配器???我已尝试并成功捕获事件,并放置了一个包含6个字段的toast…”。。。。我在尝试什么