Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在应用程序启动时删除第一次toast?_Android - Fatal编程技术网

Android 如何在应用程序启动时删除第一次toast?

Android 如何在应用程序启动时删除第一次toast?,android,Android,我正在实现微调器,我的问题是,当我启动应用程序时,它会显示toast,它会显示第一个元素。那个时候,我并没有从微调器中选择项目 我很喜欢这个。它显示了马来西亚第一次当应用程序启动 在string.xml中 <string name="country_prompt">choose country</string> <string-array name="country_arrays"> <item>Malaysia<

我正在实现微调器,我的问题是,当我启动应用程序时,它会显示toast,它会显示第一个元素。那个时候,我并没有从微调器中选择项目

我很喜欢这个。它显示了马来西亚第一次当应用程序启动

在string.xml中

 <string name="country_prompt">choose country</string>

    <string-array name="country_arrays">
        <item>Malaysia</item>
        <item>United States</item>
        <item>Indonesia</item>
        <item>France</item>
        <item>Italy</item>
        <item>Singapore</item>
        <item>New Zealand</item>
        <item>India</item>
    </string-array>


<Spinner
        android:id="@+id/spinner1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" 
        android:entries="@array/country_arrays"
        android:prompt="@string/country_prompt"

        />
选择国家
马来西亚
美国
印度尼西亚
法国
意大利
新加坡
新西兰
印度
关于java文件

setContentView(R.layout.firstactivity);
    sp= (Spinner) findViewById(R.id.spinner1);
    sp.setOnItemSelectedListener(this)

public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        // TODO Auto-generated method stub

        Toast.makeText(parent.getContext(), 
                "OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
                Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub

    }

;
setContentView(R.layout.firstactivity);
sp=(喷丝器)findViewById(R.id.spinner1);
sp.setOnItemSelectedListener(此)
已选择公共位置(AdapterView父项、视图、整数位置、长id){
//TODO自动生成的方法存根
Toast.makeText(parent.getContext(),
OnItemSelectedListener:+parent.getItemAtPosition(pos.toString(),
吐司。长度(短)。show();
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
;

据我所知,您不希望在
活动第一次运行时显示
Toast
<创建
活动
时,即使用户实际上没有选择任何内容,也会运行code>onItemSelected

哎呀,这是无法避免的。但是,您可以轻松地在中设置一个
boolean
标志,例如,
onCreate()
,并在
onItemSelected
中检查该标志,以决定是否运行代码,然后在
onItemSelected
中切换该标志

像这样的

  setContentView(R.layout.firstactivity);
    sp= (Spinner) findViewById(R.id.spinner1);
    sp.setOnItemSelectedListener(this);
    firstRun = true;   // declare this as a member variable (before onCreate())

public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        // TODO Auto-generated method stub
        if (!firstRun)
        {
            Toast.makeText(parent.getContext(), 
                "OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
                Toast.LENGTH_SHORT).show();
        }
        else
        {  firstRun = false;  }

    }
setContentView(R.layout.firstactivity);
sp=(喷丝器)findViewById(R.id.spinner1);
sp.setOnItemSelectedListener(此);
firstRun=true;//将其声明为成员变量(在onCreate()之前)
已选择公共位置(AdapterView父项、视图、整数位置、长id){
//TODO自动生成的方法存根
如果(!firstRun)
{
Toast.makeText(parent.getContext(),
OnItemSelectedListener:+parent.getItemAtPosition(pos.toString(),
吐司。长度(短)。show();
}
其他的
{firstRun=false;}
}

你能再帮我一件事吗..我需要按规定的时间间隔写文本(任何东西..因为我想检查设备是否挂起或是否正常..我使用phonegap(从服务器获取数据)在android中创建应用程序reqular间隔时间。但应用程序在10分钟后挂起,所以我需要检查每个应用程序是否在30分钟后挂起,如果我们继续写入或获取数据,我想我需要使用计时器并在fixedrate进行调度。我不太确定我是否理解您想要做的事情,但如果需要10分钟来获取数据,那么您会遇到更大的问题