toast

Checking toast message in android espresso

走远了吗. 提交于 2019-11-26 08:02:10
问题 Would anyone know how to test for the appearance of a Toast message in android espresso? In robotium its easy & I used but started working in espresso but dont getting the exact command. 回答1: This slightly long statement works for me: import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.RootMatchers.withDecorView; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android

Android cancel Toast when exiting the app and when toast is being shown

走远了吗. 提交于 2019-11-26 07:35:58
问题 I have read about this kind of problem here but the answers don\'t seem to be working. I show a Toast when user clicks a button. When the user continously clicks the button the toast keeps on being displayed again and again even when the user exits the activity. The length of the toast is short. Length of the toast cannot be changed as the text is long. This is what i have tried as of now: Toast toast; toast=Toast.makeText(getApplicationContext(),\"text\",Toast.LENGTH_SHORT); if(toast.getView

difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this

自作多情 提交于 2019-11-26 05:56:36
I'm new to android and I'm trying to understand the difference between getApplication() , getApplicationContext( ), getBaseContext() , getContext() and someClass.this and especially when to use the these methods in the following code lines: When I launch a toast what is the difference between these and in which cases to I use them? Toast.makeText(LoginActivity.this, "LogIn successful", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplication(), "LogIn successful", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "LogIn successful", Toast.LENGTH_SHORT).show(); Toast.makeText

How to display Toast in Android?

允我心安 提交于 2019-11-26 05:37:14
I have a slider that can be pulled up and then it shows a map. I can move the slider up and down to hide or show the map. When the map is on front, I can handle touch events on that map. Everytime I touch, a AsyncTask is fired up, it downloads some data and makes a Toast that displays the data. Although I start the task on touch event no toast is displayed, not till I close the slider. When the slider is closed and the map is not displayed anymore the Toast appears. Any ideas? Well start the task EDIT: public boolean onTouchEvent(MotionEvent event, MapView mapView){ if (event.getAction() == 1)

getting context in AsyncTask

眉间皱痕 提交于 2019-11-26 05:24:05
问题 I am trying to get the context in my AsyncTask of the class called Opciones(this class is the only one that call that task) but I don\'t know how to do it, I saw some code like this: protected void onPostExecute(Long result) { Toast.makeText(Opciones.this,\"Subiendo la foto. ¡Tras ser moderada empezara a ser votada!: \", Toast.LENGTH_LONG).show(); } But it doesn\'t work for me it says: \"No enclosing instance of the type Opciones in scope\" 回答1: You need to do following things. when you want

difference and when to use getApplication(), getApplicationContext(), getBaseContext() and someClass.this

这一生的挚爱 提交于 2019-11-26 01:56:14
问题 I\'m new to android and I\'m trying to understand the difference between getApplication() , getApplicationContext( ), getBaseContext() , getContext() and someClass.this and especially when to use the these methods in the following code lines: When I launch a toast what is the difference between these and in which cases to I use them? Toast.makeText(LoginActivity.this, \"LogIn successful\", Toast.LENGTH_SHORT).show(); Toast.makeText(getApplication(), \"LogIn successful\", Toast.LENGTH_SHORT)

How to display Toast in Android?

∥☆過路亽.° 提交于 2019-11-26 01:55:25
问题 I have a slider that can be pulled up and then it shows a map. I can move the slider up and down to hide or show the map. When the map is on front, I can handle touch events on that map. Everytime I touch, a AsyncTask is fired up, it downloads some data and makes a Toast that displays the data. Although I start the task on touch event no toast is displayed, not till I close the slider. When the slider is closed and the map is not displayed anymore the Toast appears. Any ideas? Well start the

How to change position of Toast in Android?

我们两清 提交于 2019-11-26 01:34:37
问题 When I use Toast to display some popup text on the screen, it displays the text a little bit above the bottom of the screen, which is the default position. Now I want to display it in the middle of screen or somewhere according to my choice. Can anyone guide me how to achieve this? 回答1: From the documentation, Positioning your Toast A standard toast notification appears near the bottom of the screen, centered horizontally. You can change this position with the setGravity(int, int, int) method

Kotlin入门(Android开发)基础知识汇总(四)之类和对象---完结篇

不想你离开。 提交于 2019-11-25 20:59:06
1.类的构造 1.1类的简单定义 //java public class MainActivity extends AppCompatActivity { ... } //Kotlin class MainActivity : AppCompatActivity() { ... } Kotlin对类的写法有以下特点: <1>省略了关键字public,缘于它默认就是开放的; <2>用冒号“:”代替extends,表示继承关系; <3>进行继承时,父类后面多了括号() class Animal { //类的初始化函数init init { //Kotlin使用println代替Java的System.out.println println("Animal:这是个动物类") } } var animal = Animal()//类的实例创建,忽略new关键字 1.2 类的构造函数 //如果主构函数没有带@符号的注解说明,constructor就可以省略 //class AnimalMain (context:Context, name:String) { class AnimalMain constructor(context:Context, name:String) { init { context.toast("这是只$name") } } //含二级构造函数 class

安卓原生记住账号密码(本地存储)

核能气质少年 提交于 2019-11-25 18:59:03
1、activity_main.xml文件样式 2、MainActivity.java主页内容 3、创建一个保存文件的类 1.activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ImageView android:id="@+id/iv" android:layout_width="70dp" android:layout_height="70dp" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:background="@drawable/dongman"/> <LinearLayout android:id="@+id/ll_number" android