2012-05-01 47 views
-1

我创建了一个时间表应用程序,它允许用户输入数据然后查看它。但是,如果用户输入一个条目,在一天和一天里已经有一个条目,我的模拟器崩溃(强制关闭)。 基本上我将数据拉回到线性布局 - 其中包含10个TextViews,每个代表9-15的时间。 下面的代码:Android试图覆盖TextViews时崩溃

 public void addMondayGrid() { 
    // TODO Auto-generated method stub 
    for (int index = 0; index < info.mon.size(); index++) { 

     // int entryId = info.monIds.get(index); 
     int time = info.monTimes.get(index); 
     int id = info.monIds.get(index); 
     int duration = info.monDuration.get(index); 
     String dayOfWeek = "mon"; 

     timeId = getResources().getIdentifier("mon" + time, "id", 
       getPackageName()); 
     if (duration == 1) { 
      SpannableString text = new SpannableString(info.mon.get(index)); 
      setEntryColour(text); 
      final TextView textV = (TextView) findViewById(timeId); 
      textV.setTextSize(10); 
      textV.setText(text, BufferType.SPANNABLE); 
      textV.setId(id); 
      deleteGridEntry(textV); 
     } else { 
      longerDuration(time, index, id, info.mon, dayOfWeek); 

     } 

    } 

} 

的事情是一样长的罚款,没有在同一天和时间,例如两项工作。星期一9点。 任何人有任何想法?我很新的这个和任何帮助将不胜感激!

我必须这样引用id,因为有太多的id来引用任何其他方式,是不是有一种简单的方法来覆盖旧的textView与从数据库拉回来的新数据?我希望id与我想要处理的textView是一样的,但它只是不断崩溃,是否与实例有关?

+0

确保TIMEID和textV是预期和非空 –

回答

1

变化:

 final TextView textV = (TextView) findViewById(timeId); 

到:

 final TextView textV = (TextView) findViewById(R.id.timeId); 
+0

我定义我所有的IDS在我的XML文件作为mon9,MON10,tue12等(我知道不好的编码),然后变量timeid确保文本设置在正确的textView,任何其他想法? – matt

+1

你需要知道如何引用xml值。尝试阅读本文:[http://developer.android.com/guide/topics/ui/declaring-layout.html](http://developer.android.com/guide/topics/ui/declaring-layout.html) – thepoosh