Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取上面的位置整数(如果在intent中没有传递额外的值,则tmpPos将为-1)。如果这样做,我会被告知“SHOWITEMINTENT\u extra\u FETCHROWID无法解析为变量”。但是我如何从已单击的ListView项中获取文本呢?别担心,_Android_Sqlite_Listview_Listener - Fatal编程技术网

Android 获取上面的位置整数(如果在intent中没有传递额外的值,则tmpPos将为-1)。如果这样做,我会被告知“SHOWITEMINTENT\u extra\u FETCHROWID无法解析为变量”。但是我如何从已单击的ListView项中获取文本呢?别担心,

Android 获取上面的位置整数(如果在intent中没有传递额外的值,则tmpPos将为-1)。如果这样做,我会被告知“SHOWITEMINTENT\u extra\u FETCHROWID无法解析为变量”。但是我如何从已单击的ListView项中获取文本呢?别担心,,android,sqlite,listview,listener,Android,Sqlite,Listview,Listener,获取上面的位置整数(如果在intent中没有传递额外的值,则tmpPos将为-1)。如果这样做,我会被告知“SHOWITEMINTENT\u extra\u FETCHROWID无法解析为变量”。但是我如何从已单击的ListView项中获取文本呢?别担心,我已经找到了它-used((TextView)v.getText().toString() public class Database extends ListActivity { private final String SAMPLE_DB


获取上面的位置整数(如果在intent中没有传递额外的值,则tmpPos将为-1)。如果这样做,我会被告知“SHOWITEMINTENT\u extra\u FETCHROWID无法解析为变量”。但是我如何从已单击的ListView项中获取文本呢?别担心,我已经找到了它-used((TextView)v.getText().toString()
public class Database extends ListActivity {

private final String SAMPLE_DB_NAME = "myFriendsDb";
//private final String SAMPLE_TABLE_NAME = "friends";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    ArrayList<String> results = new ArrayList<String>();
    SQLiteDatabase db = null;

    try {
        db =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);

        db.execSQL("CREATE TABLE IF NOT EXISTS people" +
                " (LastName VARCHAR, FirstName VARCHAR," +
                " Country VARCHAR, Age INT(3));");

        db.execSQL("INSERT INTO people" +
                " Values ('Jones','Bob','UK',30);");
        db.execSQL("INSERT INTO people" +
                " Values ('Smith','John','UK',40);");
        db.execSQL("INSERT INTO people" +
                " Values ('Thompson','James','UK',50);");

        Cursor c = db.rawQuery("SELECT FirstName, LastName FROM people", null);

        if (c != null ) {
            if  (c.moveToFirst()) {
                do {
                    String firstName = c.getString(c.getColumnIndex("FirstName"));
                    String lastName = c.getString(c.getColumnIndex("LastName"));
                    results.add("" + firstName + " " + lastName);
                }while (c.moveToNext());
            } 
        }

        this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));

    } catch (SQLiteException se ) {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database");
    } finally {
        if (db != null) 
            db.execSQL("DELETE FROM people");
            db.close();
    }
}
public class Database extends ListActivity {

    //YOUR CODE ABOVE HERE...

    public static final String SHOWITEMINTENT_EXTRA_FETCHROWID = "fetchRow";
    public static final int ACTIVITY_SHOWITEM = 0; /*Intent request user index*/

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id){
        /*
        position variable holds the position of item you clicked...
        do your stuff here. If you want to send to another page, say another activity
        that shows your stuff, you can always use an intent
        example:
        */
        Intent tmpIntent = new Intent(this, YourActivityForShowingItem.class);
        tmpIntent.putExtra(SHOWITEMINTENT_EXTRA_FETCHROWID, position);
        startActivityForResult(tmpIntent, ACTIVITY_SHOWITEM);

    }
}
private void setMyListListener(){
    getListView().setOnItemClickListener(new OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> a, View v, int position, long id){
            /*same fake code as above for calling another activity using an intent:*/
            Intent tmpIntent = new Intent(this, YourActivityForShowingItem.class);
            tmpIntent.putExtra(SHOWITEMINTENT_EXTRA_FETCHROWID, position);
            startActivityForResult(tmpIntent, ACTIVITY_SHOWITEM);
        }
    });
}