toast

using a string resource in a Toast

淺唱寂寞╮ 提交于 2019-11-29 13:21:48
My code is: public static void ToastMemoryShort (Context context) { CharSequence text = getString(R.string.toast_memoryshort); //error here Toast.makeText(context, text, Toast.LENGTH_LONG).show(); return; } but I'm getting "Cannot make a static reference to the non-static method getString(int) from the type Context" in Eclipse. I'm trying to get ready for localising my app (getting all the hard coded strings into resources), so where I have: getString(R.string.toast_memoryshort) I previously had a hard coded string which was fine. I'm not sure what's going on here (Java noob). Can anyone

Toast from a Non-UI thread [duplicate]

不羁岁月 提交于 2019-11-29 12:51:38
Possible Duplicate: Android: Toast in a thread I am calling a helper class function from a worker thread, wherein I am trying to raise a toast but I am getting following exception Android Can't create handler inside thread that has not called Looper.prepare Can't we raise a toast from a Non UI thread ? You can use runOnUiThread() For example this.runOnUiThread(show_toast); and in show_toast private Runnable show_toast = new Runnable() { public void run() { Toast.makeText(Autoamtion.this, "My Toast message", Toast.LENGTH_SHORT) .show(); } }; 来源: https://stackoverflow.com/questions/13267239

Android 给Button加个监听

和自甴很熟 提交于 2019-11-29 11:55:49
在 Android 开 发过程中,Button是常用的控件,用起来也很简单,你可以在界面xml描述文档中定义,也可以在程序中创建后加入到界面中,其效果都是一样的。不过最 好是在xml文档中定义,因为一旦界面要改变是话,直接修改一下xml就行了,不用修改Java程序,并且在xml中定义层次分明,一目了然。另一个是如 果在程序中定义,还要将其加入到界面中,有的还要设置高度宽度,样式之类的,会使程序变得臃肿,开发和维护都不方便。 我们先在程序中定义一个Button Button button = new Button(this);//定义一个button,其中this是上下文,这段代码是在一个Activity的onCreate中创建的。 button.setWidth(100);//一定要设置宽和高。不然会出错的。 button.setHeight(50); button.setText(“Click me”);//按钮上的文字 RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.buttonLayout); relativeLayout.addView(button);//加到界面中 以下是在UI xml中定义的按钮。 android:orientation=”horizontal” android

How to cancel Toast created in a different method on android?

♀尐吖头ヾ 提交于 2019-11-29 10:02:15
I have the following code: private Toast movieRecordToast; private void displayNextMovie() { if (movieRecordToast != null) movieRecordToast.cancel(); // cancel previous Toast (if user changes movies too often) movieRecordToast = Toast.makeText(getApplicationContext(), "Next", Toast.LENGTH_SHORT); movieRecordToast.show(); private void displayPrevMovie() { if (movieRecordToast != null) movieRecordToast.cancel(); movieRecordToast = Toast.makeText(getApplicationContext(), "Prev", Toast.LENGTH_SHORT); movieRecordToast.show(); But if displayNextMovie is called quickly several times and then

后端spring boot+前端Android交互+mysql增删查改

前提是你 提交于 2019-11-29 09:56:29
1.概述 使用spring boot作为后端框架与Android端配合mysql进行基本的交互,包含了最基本的增删查改功能. 2.开发环境 win10 IDEA tomcat9.0.27 mysql8.0.17 spring boot 3.后端 (1)新建一个spring boot项目 可以看这里 (2)Entity 新建User类作为实体类: package com.test; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Integer id; private String name; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void

第三次作业

巧了我就是萌 提交于 2019-11-29 08:18:00
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:orientation="vertical" android:padding="30dp"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:drawableLeft="@drawable/bg" android:text="QQ" android:textSize="50sp" /> <EditText android

第三次作业

别说谁变了你拦得住时间么 提交于 2019-11-29 08:14:29
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:orientation="vertical" android:padding="30dp"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:drawableLeft="@mipmap/o1" android:text="QQ" android:textSize="50sp" /> <EditText android

第三次作业

本秂侑毒 提交于 2019-11-29 08:10:01
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/p4"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:orientation="vertical" android:padding="30dp"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="100dp" android:drawableLeft="@mipmap/p1" android:text="QQ" android

Toast.makeText from resource string

流过昼夜 提交于 2019-11-29 04:13:09
问题 I have a class named MyPrimaryClass, this class has a button witch when pressed, creates an Intent with the class myClassForResult. I use this to start it: startActivityForResult(myIntentOfMyClassForResult, ACTIVITY_EDIT_BTEXT); Both MyPrimaryClass, and myClassForResult extends Activity. So, when I call Toast.makeText within the myClassForResult, with the text parameter of R.string.my_resource_string, it gives me Force Close! I have tried this: Context c = myClassForResult.this; Toast toast =

How to display a Toast message in from a class that doesn't extend Activity [duplicate]

空扰寡人 提交于 2019-11-29 03:53:33
Possible Duplicate: How do I make a toast from a non activity class? How can I create and show a Toast message from a class which does not extended the Activity class? I'm using this class in another class that is extended by Activity . You need a context Reference. Just have a helper method like public static void showToastMethod(Context context) { Toast.makeText(context, "mymessage ", Toast.LENGTH_SHORT).show(); } You can pass context of that activity to your class by passing value to nonActivity class example: new NonActivityClass(Activityclass.this) ; and as in above answer new MyClass