2011-06-04 19 views
5

मुझे अपने ऐप में कोई समस्या है। मेरे पास कुछ सूचियां हैं और उनमें से प्रत्येक की तारीख है। यदि सूची की तारीख आज है तो मैंने अधिसूचना की है, और मेरी अधिसूचना में मैंने आइटम को उस सूची से रखा है। समस्या यह है कि यदि मेरी सूची खाली है तो मुझे बल मिल जाएगा। मैंने स्थिति को केवल तभी नोटिफिकेशन करने के लिए रखा जब कर्सर शून्य नहीं है, लेकिन ऐसा लगता है कि यह काम नहीं करता है। क्या आप यह जानने में मदद कर सकते हैं कि समस्या कहां है? डेटा प्राप्त करने से पहले()एंड्रॉइड में शून्य कर्सर

if (cr != null && cr.moveToFirst()) { 
    // ... 
} 

आप moveToFirst की जरूरत है:

cr = db.fetchListId(id); 
startManagingCursor(cr); 

s = new StringBuilder(100); 
if (cr != null) { 
    do { 
    String myList = ""; 
    myList += cr.getString(2) + " " + cr.getString(3) 
     + cr.getString(4) + "," + "\n"; 
    s.append(myList); 

    } while (cr.moveToNext()); 
    s.append('.'); 
    System.out.println("!!heyeheeye!" + s + "!!!!"); 
    hey(list); 
} 

where hey(list) is a function where is made the notification. 

    private void hey(String list) { 
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    CharSequence NotificationTicket = "Hey"; 

    long when = System.currentTimeMillis(); 

    Notification notification = new Notification(R.drawable.icon, 
               NotificationTicket, when); 

    RemoteViews contentView = new RemoteViews(getPackageName(), 
              R.layout.proba); 
    contentView.setImageViewResource(R.id.image, R.drawable.icon); 
    contentView.setTextViewText(R.id.notif, 
           "Today,you must go for shopping for your list '" + list + "'. " 
           + "Don't forget!!!" + "\n" + "You must buy :" + "\n" 
           + s.toString() + "\n"); 
    notification.contentView = contentView; 


    Context context = getApplicationContext(); 

    Intent notifyIntent = new Intent(context, Lists.class); 

    Intent notificationIntent = new Intent(this, Lists.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
                  notificationIntent, 0); 
    notification.contentIntent = contentIntent; 

    notificationManager.notify(ID_NOTIFICATION, notification); 
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 


       | Intent.FLAG_ACTIVITY_SINGLE_TOP); 
} 

उत्तर

6

निम्नलिखित जाँच करें अगर कर्सर किसी भी परिणाम को देखने के लिए:

यहाँ कोड का एक हिस्सा है। क्योंकि आप एक काम का उपयोग कर रहे हैं ... जबकि जबकि() के बजाय, आप कर्सर को ठीक से शुरू नहीं कर रहे हैं।

+0

धन्यवाद। तुम ठीक हो.अब, यह काम करता है .. – Gaby

संबंधित मुद्दे