It definitely can be made to work. Here is an example:
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast_layout, null);
TextView text = (TextView) layout.findViewById(R.id.toast_text);
text.setText(msg);
Toast toast = new Toast(context.getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
Where toast_layout.xml is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:drawable/toast_frame">
<!-- Stuff removed for clarity -->
<TextView
android:id="@+id/toast_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="?android:attr/colorForegroundInverse" />
</LinearLayout>
Note that the textview is assigned an id ("@+id/toast_text") which is
thenu used in the code.
-- Kostya
10.03.2011 4:29, kiros88 пишет:
Hey Im trying to figure out y this is giving me a null pointer error
basically Im trying to do this example ont he developers website
http://developer.android.com/guide/topics/ui/notifiers/toasts.html
the part where ist like custom views, Im only doing the text part so u
can skip the image stuff
but the problem is that when i put in the text like set text.setText()
its just a null pointer towards the textView in the .xml so iono what
hte problem could be i basically copied the code on the wwebsite and
put it on the onCreate() function in my main and yea i cant seem to
get the TextView to work
--
Kostya Vasilyev -- http://kmansoft.wordpress.com
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en