2015-10-06 43 views
-2

文本崩潰我有以下XML文件的EditText使得應用程序時引入的,而不是一個數量

<?xml version="1.0" encoding="utf-8"?> 

<string-array name="my_array"> 

    <item>rome 999 3 4 5 7 9 11 17</item> 

</string-array> 

,我用它來初始化一個SQLite表此結構:

public static abstract class FeedEntry implements BaseColumns { 
    public static final String TABLE_NAME = "entry"; 
    public static final String COLUMN_NAME_ENTRY_ID = "entryid"; 
    public static final String COLUMN_NAME_TITLE = "title"; 
    public static final String COLUMN_NAME_SCHEDULE = "schedule"; 
} 

這是我分析的值並把它們放在桌子現在

for (String item : myArray){ 
     String[] split = item.split("\\s+"); 

     values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID, split[0]); 
     values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE, split[1]); 
     String schedule=""; 

     String[] stringArray = item.split("\\s+"); 
     int length = stringArray.length; 

     for (int i = 2; i < length; i++) { 
      System.out.println(i); 
      if(schedule.trim().length()>0){ 
       schedule += split[i]+" "; 
      }else{ 
       schedule = split[i]; 
      } 
     } 


     values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_SCHEDULE, schedule); 
     db.insert(FeedReaderContract.FeedEntry.TABLE_NAME, null, values); 
    } 

的代碼,在那之後我就成爲一個sqlite的要求如:

 Cursor cursor = db.query(
      FeedReaderContract.FeedEntry.TABLE_NAME, 
      projection,        
      FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE+" = " + string ,        
      null,        
      null,          
      null,         
      sortOrder         
    ); 

我使用光標創建在這樣新的EditText:

for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()){ 
      result = result + cursor.getString(iRow) + " " + cursor.getString(iName) + 
        " " + cursor.getString(iSchedule) + 
        "\n"; 
     } 
TextView textview = new TextView(getApplicationContext()); 
     textview.setText(result); 
     RelativeLayout myLayout; 
     myLayout = (RelativeLayout) findViewById(R.id.content_main); 
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 

TextView tv = (TextView) findViewById(R.id.button); 
     textview.setTextColor(Color.RED); 
     params.addRule(RelativeLayout.BELOW, tv.getId()); 
     myLayout.addView(textview, params); 

但是,如果我改變在XML文件中,我介紹的第二個元素文本,例如像:

<?xml version="1.0" encoding="utf-8"?> 

<string-array name="my_array"> 

    <item>rome line1 3 4 5 7 9 11 17</item> 

</string-array> 

如果我重複的東西,讓我通過查找文本line1,應用程序崩潰的sqlite的請求。即在上面的代碼中,sqlite只是期望一個數字而不是文本。我不明白這種行爲的起源。另外,我怎樣才能使它與文本一起工作呢?

+0

燦您將代碼發佈到實際解析字符串並將其寫入數據庫的位置? – phxhawke

+0

@phxhawke剛剛完成 – Helios83

回答

0

我的猜測是,你希望羅馬顯示爲標題,而不是999。如果是這樣的話那麼最簡單的解決將是改變你的字符串數組改爲

<item>999 Rome 3 4 5 7 9 11 17</item>

相關問題