Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.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 显示不断更新的文本的最佳方式是什么_Android_Textview - Fatal编程技术网

Android 显示不断更新的文本的最佳方式是什么

Android 显示不断更新的文本的最佳方式是什么,android,textview,Android,Textview,我想显示一些文本,指示我的应用程序的进度。文本不断更新,这意味着我将继续附加到它。我使用过textView,但当文本超出其大小时,应用程序崩溃。那么,显示此类文本的最佳方式是什么 注意:在包含文本的活动中,除了文本视图和按钮之外,我没有任何其他项目 这是尚未创建按钮的活动的xml文件 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.andro

我想显示一些文本,指示我的应用程序的进度。文本不断更新,这意味着我将继续附加到它。我使用过textView,但当文本超出其大小时,应用程序崩溃。那么,显示此类文本的最佳方式是什么

注意:在包含文本的活动中,除了文本视图和按钮之外,我没有任何其他项目

这是尚未创建按钮的活动的xml文件

<ScrollView 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=".Locate" >

  <LinearLayout android:id="@+id/scrollBody"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
   <TextView
    android:id="@+id/log"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:layout_marginTop="20dp"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceMedium" />
      </LinearLayout>

这是我的密码

public class Locate extends Activity {

    List<ScanResult> wifiList;
    Timer timer ;
    public static int counter;
    int interval;
    int scansPerLoc;
    StringBuilder Res;
    boolean scanning;
    int port;
    String IP;
    private Socket client;

    private WifiManager Wifi;
    private WifiReceiver receiverWifi;
    private IntentFilter filter;
    private Toast toast;
    private Context context;
    private TextView log;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_locate);

        counter=0;
        // setting the android environment 
        context=this;
        Wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        filter= new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
        timer = new Timer();
        Res = new StringBuilder();
        scanning=false;
        receiverWifi = new WifiReceiver();
        registerReceiver(receiverWifi, filter);

        log=(TextView)findViewById(R.id.log);
        log.append("Locator:\n");
        toast=Toast.makeText(context, "Locating", Toast.LENGTH_SHORT);
        toast.show();

        //setting pars
    if(Settings.setting==true)
    {
          interval=Settings.interval;
        scansPerLoc=Settings.scansPerLoc;

    }
    else
    {
         interval=200;
         scansPerLoc=5;
    }


    receiverWifi = new WifiReceiver();
    registerReceiver(receiverWifi, filter);
    Wifi.startScan();


    toast=Toast.makeText(context, interval +"  "+scansPerLoc, Toast.LENGTH_SHORT);
    toast.show();


    if(scanning)
    {
           timer.cancel();
    }
    else 
    {

        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                if(counter==scansPerLoc)
                {
                    scanning=false;
                    timer.cancel();
                    log.append("Finished Collecting RSSIs.");
                }
                else
                {

                    scanning=true;
                    if(wifiList!=null)
                    {
                        if(wifiList.size()!=0)
                        for(int i=0;i< wifiList.size();i++)
                        {
                            log.append((i+1)+" "+wifiList.get(i).BSSID+" "+wifiList.get(i).level+" ");
                            Res.append((i+1)+" "+wifiList.get(i).BSSID+" "+wifiList.get(i).level+" ");
                        //  format i : BSSID : RSSI : i :BSSID : RSSI
                        }

                    }
                    else
                    {
                        Res.append("Empty");
                        log.append("No results");
                    }


                }
            }
        },0,interval);
    }

    if(counter==scansPerLoc)
    {
        if(!Settings.setting)
        {
            //show and ask for the settings
            toast=Toast.makeText(context, "The server parameters are not set yet, please set them", Toast.LENGTH_LONG);
            toast.show();

        }
        else
        {

        }
    }


    }// end of on create

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.locate, menu);
        return true;
    }


    class WifiReceiver extends BroadcastReceiver {

        public void onReceive(Context c, Intent intent) {

          wifiList=Wifi.getScanResults();



        }//end of on receive

  }// end of class


      protected void onPause() {
            unregisterReceiver(receiverWifi);

            super.onPause();
        }

        protected void onResume()
        {
            registerReceiver(receiverWifi,filter);
            super.onResume();
        }
}
公共类定位扩展活动{
列表wifiList;
定时器;
公共静态计数器;
整数区间;
int-scansPerLoc;
StringBuilder Res;
布尔扫描;
国际港口;
字符串IP;
专用套接字客户端;
私人WifiManager-Wifi;
私人无线接收器无线;
专用过滤器;
私人吐司;
私人语境;
私有文本视图日志;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_locate);
计数器=0;
//设置android环境
上下文=这个;
Wifi=(WifiManager)getSystemService(Context.Wifi\u服务);
过滤器=新的意向过滤器(WifiManager.SCAN\u RESULTS\u AVAILABLE\u ACTION);
定时器=新定时器();
Res=新的StringBuilder();
扫描=假;
receiverWifi=新WifiReceiver();
注册接收者(接收者、过滤器);
log=(TextView)findViewById(R.id.log);
log.append(“定位器:\n”);
toast=toast.makeText(上下文,“定位”,toast.LENGTH\u SHORT);
toast.show();
//设置PAR
if(Settings.setting==true)
{
间隔=设置。间隔;
scansPerLoc=Settings.scansPerLoc;
}
其他的
{
间隔=200;
scansPerLoc=5;
}
receiverWifi=新WifiReceiver();
注册接收者(接收者、过滤器);
Wifi.startScan();
toast=toast.makeText(上下文,间隔+“”+scansPerLoc,toast.LENGTH\u SHORT);
toast.show();
如果(扫描)
{
timer.cancel();
}
其他的
{
timer.schedule(新TimerTask(){
@凌驾
公开募捐{
//TODO自动生成的方法存根
如果(计数器==scansPerLoc)
{
扫描=假;
timer.cancel();
log.append(“已完成收集RSSIs”);
}
其他的
{
扫描=真;
如果(wifiList!=null)
{
如果(wifiList.size()!=0)
对于(int i=0;i
您能用您已有的代码说明您的问题吗?您可以使用,它支持多行text@Melquiades我已经添加了代码,是否有所有以前的更新消息是至关重要的?如果您只需要最后一个,甚至是最后10个、20个或50个,那么就可以避免内存问题。其他选项可能是将旧邮件归档到文件中,然后在滚动备份时恢复它们。如果你找不到你要找的答案,就有几个选择。@PulkitSethi我想我会把更新写到一个文件中