2016-03-30 55 views
-2

所有緯度值我從SQLite數據庫檢索緯度數據。如何顯示從這個

我有一張表,裏面填充了經度和緯度值。

我的查詢是:

public Cursor fetchAllCountries() { 
    SQLiteDatabase db=this.getReadableDatabase(); 
    String SelectQuery="select * from "+ TABLE_NAME; 
    Cursor mCursor = db.rawQuery(SelectQuery,null); 
    if (mCursor != null) { 
     mCursor.moveToFirst(); 
    } 
    return mCursor; 
} 

MainActivity.java包含:

Cursor cursor = myDB.fetchAllCountries(); 

/* for (int i=0;i<list.size();i++) { 
    double data=list.get(i); 
    System.out.println(data + " "); 
}*/ 

if (cursor.moveToFirst()) { 
    do { 
     double data = cursor.getDouble(cursor.getColumnIndex("lat")); 
     System.out.println(data + " "); 
    } while(cursor.moveToNext()); 
} 
+0

是什麼的問題,什麼是叔他有問題嗎? – k0sh

+2

這是不完全清楚你在這裏試圖完成。你想在哪裏顯示緯度?看起來你有代碼應該編譯並做你需要的代碼。你問如何顯示它在Android本身(因爲你正在輸出到標準輸出目前 – Knossos

+0

SIr @Knossos,是的,我想訪問來自javascript的lat長期值,但目前我想顯示它在Android本身 – Varma

回答

0
public Cursor fetchAllCountries() { 
    SQLiteDatabase db=this.getReadableDatabase(); 
    String SelectQuery="select * from "+ TABLE_NAME; 
    Cursor mCursor = db.rawQuery(SelectQuery,null); 
    if (mCursor != null) { 
     mCursor.moveToFirst(); 
    } 
    return mCursor; 
} 

MainActivity.java

TextView txt = (TextView) findViewById(R.id.textView); 
Cursor cursor = myDB.fetchAllCountries(); 

double[] array = new double[cursor.getCount()]; 
int i = 0; 

if (cursor.moveToFirst()) { 
    do { 
     double data = cursor.getDouble(cursor.getColumnIndex("lat")); 
     array[i] = data; 
     txt.append(Double.toString(array[i])); 

     i++; 
    } while (cursor.moveToNext()); 
} 
-1

這是一個例子。

private static List<Information> getAllInformation(Cursor cursor) { 
    List<Information> list = new ArrayList<>(); 
    if (cursor != null) { 
     if (cursor.moveToFirst()) { 
      do { 
       int id = cursor.getInt(cursor.getColumnIndex(COL_ID)); 
       String title = cursor.getString(cursor.getColumnIndex(COL_TITLE)); 
       String mediaName = cursor.getString(cursor.getColumnIndex(COL_MEDIA_NAME)); 
    Information info = new Information(id, title, mediaName); 
       list.add(info); 
      } while (cursor.moveToNext()); 
     } 
     if (!cursor.isClosed()) { 
      cursor.close(); 
     } 
    } 
    return list; 
} 

public static List<Information> getAllInformation() { 
    String sql = "SELECT * FROM " + TABLE_NAME; 
    SQLiteDatabase database = this.getReadableDatabase(); 
    Cursor cursor = database.rawQuery(sql, null); 
    return getAllInformation(cursor); 
} 

在活動

List<Information> mListAll; 
mListAll = YourNameTable.getAllInformation(); 

類Information.class

public class Information { 
int id; 
String title; 
String mediaName; 

//get 
//set 

} 
+0

先生我得到一個錯誤信息可能我知道它是什麼,android工作室問我添加類信息那樣,謝謝 – Varma

+0

我更新我的答案 –

+0

謝謝先生.. – Varma