我想显示一些指示我的应用程序进度的文本。文本不断更新,这意味着我将继续追加它。我已经使用了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();
}
}