toast

第八次作业

早过忘川 提交于 2019-12-03 14:43:16
<?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" android:background="#E6E6E6" tools:context=".MainActivity"> <ImageView android:id="@+id/iv_head" android:layout_width="50dp" android:layout_height="50dp" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:src="@drawable/dddss" /> <LinearLayout android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="wrap

Error while dispaying an Toast message: Can't create handler inside thread that has not called Looper.prepare()

耗尽温柔 提交于 2019-12-03 14:14:47
I am getting an Runtime Exception:Can't create handler inside thread that has not called Looper.prepare() while displaying the Toast message in a worker thread. I have a service (runs in a remote process) which creates an object. This object is responsible for connecting to a server in a thread. I get the response from the sever. I want to display the message from the server in the toast. At that time I getting this exception. I tried posting it in a Handler by using handler.post. But still i am getting the exception. What should be the approach to avoid this. Define a Handler like this:

ActionbarSherlock: Long-click on action item show a Toast?

眉间皱痕 提交于 2019-12-03 13:56:59
问题 When an action item is long-clicked, a Toast without text is show below the action item. Can I disable the Toast ? Thanks you. 回答1: If you omit a title or specify that the action item should be displayed with text then long-pressing will not toast. Otherwise the toast adds clarification of what each action item represents. 回答2: Using this answer to get the action bar view: https://stackoverflow.com/a/21125631/555914 I used this to disable the toast: View actionBar = AppUtils.getActionBarView

第九次作业

流过昼夜 提交于 2019-12-03 13:54:07
<?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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.itcase.directory.MainActivity"> <LinearLayout android:id="@+id/linearlayout1" android:layout_width="match_parent" android

android toast doesn't fit text

风流意气都作罢 提交于 2019-12-03 13:45:22
I am developing an application where I have to use numerous toasts. I display these toasts by using: Toast.makeText(context, "Some medium-sized text", Toast.LENGTH_SHORT).show(); The displayer toast, however, has the height of one line, while the text is displayed on multiple lines. The result is that I can't view all the text in the toast. How can I fix this? Merlin Try inserting a carriage-return and line-feed where you want to split the text. These characters refer back to the old typewriter models. Carriage return was the cylinder moving back to the start and line feed was the cylinder

兔子--如何模拟耗时操作?

瘦欲@ 提交于 2019-12-03 11:55:53
public void longRunning(long time) { Toast.makeText(this, "----耗时任务开始执行---", Toast.LENGTH_SHORT).show(); long endTime = System.currentTimeMillis() + time; while (System.currentTimeMillis() < endTime) { synchronized (this) { try { wait(endTime - System.currentTimeMillis()); } catch (Exception e) { } } } Toast.makeText(this, "----耗时任务执行完成---", Toast.LENGTH_SHORT).show(); } 来源: CSDN 作者: 王立平123 链接: https://blog.csdn.net/u013425527/article/details/48466123

Android 处理耗时操作之二------AsyncTask

孤街浪徒 提交于 2019-12-03 11:54:22
为了更方便的处理一些耗时操作,android提供了一些好用的工具,比如AsyncTask。借助这个就可以简单的从子线程切换到主线程。 当然这个工具也是基于异步消息处理机制的,只是安卓做了很好的封装。 首先要说明的是AsyncTask是一个抽线类,要使用它,就必须先创建一个子类再去实现实现相关功能 该抽象类的声明如下 public abstract class AsyncTask<Params, Progress, Result> Params: 开始异步任务执行时传入的参数类型; Progress: 异步任务执行过程中,返回下载进度值的类型; Result: 异步任务执行完成后,返回的结果类型; 一个简单的自定义类可以这么写 class MyTask extends AsyncTask<Void, Integer, Boolean> 这里将传入参数设置为空,是因为我们暂时不需要传入参数给后台任务 当然现在的我们自定义的类还只能算是一个空任务,内在并没有什么逻辑。为了能让我们的自定义类担当大任我们还需要重写几个方法 1.onPreExecute() 这个方法会在 后台任务开始执行之间调用,在主线程执行。 用于进行一些界面上的初始化操作,比如显示一个进度条对话框等。 2.doInBackground(Params) 这个方法中的所有代码都会在子线程中运行

第八次作业

北城以北 提交于 2019-12-03 11:23:58
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" tools:context=".MainActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginTop="50dp" android:src="@drawable/qq" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="30dp"> <TextView

09

一曲冷凌霜 提交于 2019-12-03 10:42:38
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.phonedata.MainActivity" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout

getSelectedItemPosition() always return -1

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a class that extends ListActivity, its work fine Then in the onListItemClick() I use getSelectedItemPosition() and its always return -1 P.S getSelectedItemId() return some long number like 994393434 public class TasksShowActivity extends ListActivity { private Cursor mCursor; private ListAdapter mAdapter; private static final String[] mContent = new String[] { TasksDbHelper._ID, TasksDbHelper.NAME, TasksDbHelper.USER}; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mCursor = managedQuery(