Android، كيفية نخي فئة SimpleXML الخاصة بي؟
-
14-11-2019 - |
سؤال
آسف، أنا جديد جدا في Android ... لدي نشاط يقوم بإنشاء مثيل كائن من صفي: giveacodicetagpre.
كيف يمكنني استخدام فئة Toast (أو أي فئة UIA) في عملي الفني للفئة، والتي لا أقوم بها أبدا، لكنها تم إنشاؤها بشكل غير مباشر من خلال مكالمة إلى Serial.Read (Artworks.class)؟ كيف أفعل ذلك، بالضبط؟
شكرا مقدما!
المحلول
You can use a "static" helper class to maintain a static reference to your Activity's context. So, before you deserialize your Artwork class, call UtilClass.setContext(getApplicationContext());
. Then, within your Artwork class, you can retrieve that context and then do something like Toast.makeText(UtilClass.getContext(), "text", Toast.LENGTH_LONG).show();
.
نصائح أخرى
import android.widget.Toast;
public class Artwork {
Toast.makeText(Artwork.this, "text", Toast.LENGTH_LONG).show();
}
لا تنتمي إلى StackOverflow