当前位置:  编程技术>移动开发
本页文章导读:
    ▪遍历指定目录上的文件,将复合条件的文件加载到列表(UITableView))        遍历指定目录下的文件,将复合条件的文件加载到列表(UITableView)) 本站最新网址:[url]http://www.helmsmansoft.com [/url] 欢迎关注 - (void)viewDidLoad { NSFileManager *fileManager = [[NSFileManager defaultManager] ini.........
    ▪ 奇怪奇怪的有关问题        奇怪奇怪的问题 由于需求,我自己写了一个MyDialog extends Dialog 在Dialog里面写了一个handler,用来更新Dialog上的字。 第二次更新界面,需要Dialog比第一次变大点。     可是Dialog在Activity里面显.........
    ▪ 温度曲线 屉子       温度曲线 抽屉 实现天气预报温度曲线绘制及抽屉效果显示:package com.canvas;import android.app.Activity;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Mat.........

[1]遍历指定目录上的文件,将复合条件的文件加载到列表(UITableView))
    来源: 互联网  发布时间: 2014-02-18
遍历指定目录下的文件,将复合条件的文件加载到列表(UITableView))
本站最新网址:[url]http://www.helmsmansoft.com [/url] 欢迎关注

- (void)viewDidLoad
{
    NSFileManager *fileManager = [[NSFileManager defaultManager] init];
    everyTitle = [[NSMutableArray alloc] init];
    NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *filePath = [filePaths objectAtIndex:0];
//    NSLog(@"%@",filePath);
    NSDirectoryEnumerator *direnum = [fileManager enumeratorAtPath:filePath];
    //    NSMutableArray *array = [[NSMutableArray alloc] init];
    NSString *fileName;
    while ((fileName = [direnum nextObject])) {
        if([[fileName pathExtension] isEqualToString:@"pdf"]){
            
            NSArray *strings = [fileName componentsSeparatedByString:@"."];
            NSString *fileTitle = [strings objectAtIndex:[strings count]-2];
       
            [everyTitle addObject:fileTitle];
        
        }
    }
    
    uiController = [[UIViewController alloc] init];
    [uiController setTitle:@"目录"];
    
    navController = [[UINavigationController alloc] initWithRootViewController:uiController];
    navController.view.frame = CGRectMake(0, 0, 320, 460);
    [self.view addSubview:navController.view];
    
    self.uiController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(tableUpdata)];
//    
    self.uiController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"刷新列表" style:UIBarButtonItemStyleBordered target:self action:@selector(tableUpdata)];
    
    tableView *tableViews = [[tableView alloc] initWithStyle:UITableViewStylePlain];
    tableViews.view.frame = CGRectMake(0, 45, 320, 460);
    [tableViews theValue:everyTitle];
    [self.view addSubview:tableViews.view];
//    [tableViews release];
    

}

    
[2] 奇怪奇怪的有关问题
    来源: 互联网  发布时间: 2014-02-18
奇怪奇怪的问题

由于需求,我自己写了一个MyDialog extends Dialog

在Dialog里面写了一个handler,用来更新Dialog上的字。

第二次更新界面,需要Dialog比第一次变大点。

 

 

可是Dialog在Activity里面显示,

如果activity不挂后台的话,更新很正常。

但是我把activity挂后台的话,Dialog的大小不变,使得我的TextView没办法完全显示%>_<%

 

看来还得另想办法解决BadToken!!!

 

一个问题,如果Activity挂了,Dialog还能继续显示么????


    
[3] 温度曲线 屉子
    来源: 互联网  发布时间: 2014-02-18
温度曲线 抽屉
实现天气预报温度曲线绘制及抽屉效果显示:
package com.canvas;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.Toast;

public class AndroidCanvasActivity extends Activity {
private float tempLow[] = {10,24,15,23};
private float tempHigh[] = {33,40,33,34};
private float temp[] = {33,40,33,34,10,24,15,23};

private View view;
private LinearLayout llLayout,llLayout2;
private int screenWith,screenHeight;
float lowDis = 0,highDis = 0;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
//        view = findViewById(R.id.view);
        llLayout = (LinearLayout) findViewById(R.id.content);
        llLayout2 = (LinearLayout) findViewById(R.id.ll);
       
        Object  object = getSystemService(WINDOW_SERVICE);
        WindowManager wm = (WindowManager) object;
        screenWith = wm.getDefaultDisplay().getWidth();
        screenHeight = wm.getDefaultDisplay().getHeight();
       
        llLayout.addView(new DrawView(this));
        llLayout2.addView(new DrawView(this));
    }
    class DrawView1 extends SurfaceView implements SurfaceHolder.Callback, Runnable{

    float circleX = screenWith / 16;//屏幕横向8等分
    float circleY = 260.0f*screenHeight/480.0f;
    private SurfaceHolder surfaceHolder;
public DrawView1(Context context) {
super(context);
surfaceHolder = this.getHolder();
surfaceHolder.addCallback(this);
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
new Thread(this).start();
}

@Override
public void surfaceCreated(SurfaceHolder holder) {

}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}

@Override
public void run() {
while (!Thread.currentThread().interrupted()) {
synchronized (surfaceHolder) {
draw();
}
}
}
private void draw(){
Canvas canvas = null;
Matrix matrix = new Matrix();
if(!Thread.currentThread().interrupted()){
canvas = surfaceHolder.lockCanvas();
canvas.drawColor(Color.BLUE);
matrix.preTranslate(100f, 100f);

Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.RED);
    paint.setStyle(Style.FILL);
   
    Paint linePaint = new Paint();
    linePaint.setAntiAlias(true);
    linePaint.setColor(Color.YELLOW);
   
    Paint textPaint = new Paint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(8.0f);
   
    for (int i = 0; i < tempLow.length; i++) {
canvas.drawCircle(circleX + i*circleX, tempLow[i]*5, 2, paint);
canvas.drawText(tempLow[i]+"°", circleX + i*circleX, tempLow[i]*5-10, textPaint);
if(i < tempLow.length - 1){
canvas.drawLine(circleX + i*circleX,tempLow[i]*5, circleX + (i+1)*circleX, tempLow[i+1]*5, linePaint);
}
}
    for (int i = 0; i < tempHigh.length; i++) {
canvas.drawCircle(circleX + i*circleX, tempHigh[i]*5, 2, paint);
canvas.drawText(tempHigh[i]+"°", circleX + i*circleX, tempHigh[i]*5-10, textPaint);
                if(i < tempLow.length - 1){
canvas.drawLine(circleX + i*circleX,tempHigh[i]*5, circleX + (i+1)*circleX, tempHigh[i+1]*5, linePaint);
}
}
}
canvas.setMatrix(matrix);
if(canvas != null){

surfaceHolder.unlockCanvasAndPost(canvas);
}
}
   
    }
    class DrawView extends View{

    float circleX = screenWith / 16;//屏幕横向8等分
    float circleY = 260.0f*screenHeight/480.0f;
    float[] sortData = sort(temp);
public DrawView(Context context) {
super(context);
}
    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    float highPx = 260.0f*screenHeight/480.0f;
    float lowPx = 80.0f*screenHeight/480.0f;
   
    float x0 = screenWith/16;//40.0f
    float x1 = 3*x0;
    float x2 = 5*x0;
    float x3 = 7*x0;
   
    //乘100再除100是未了保留精度
    float y0 = highPx - (100*(tempHigh[0]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
    float y1 = highPx - (100*(tempHigh[1]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
    float y2 = highPx - (100*(tempHigh[2]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
    float y3 = highPx - (100*(tempHigh[3]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
   
    float y00 = highPx - (100*(tempLow[0]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
    float y11 = highPx - (100*(tempLow[1]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
    float y22 = highPx - (100*(tempLow[2]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
    float y33 = highPx - (100*(tempLow[3]-sortData[0])/(sortData[7]-sortData[0])*(highPx-lowPx)/100);
   
   
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.WHITE);
   
    Paint linePaint = new Paint();
    linePaint.setAntiAlias(true);
    linePaint.setColor(Color.YELLOW);
    linePaint.setTextSize(5.0f);
   
    Paint textPaint = new Paint();
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.WHITE);
    textPaint.setTextSize(10.0f);
   
    float pts1[] = {x0,y0,x1,y1,
        x1,y1,x2,y2,
        x2,y2,x3,y3
        };
   
    float pts2[] = {
    x0,y00,x1,y11,
        x1,y11,x2,y22,
        x2,y22,x3,y33
        };
   
    linePaint.setColor(Color.YELLOW );;//
    canvas.drawLines(pts1, linePaint);
    linePaint.setColor(Color.GREEN);;//
    canvas.drawLines(pts2, linePaint);
   
    float radius = 5.0f;
//    canvas.drawPoints(pts1, pointPaint);
    paint.setColor(Color.WHITE);;//
    canvas.drawCircle(x0, y0, radius, paint);
    canvas.drawCircle(x1, y1, radius, paint);
    canvas.drawCircle(x2, y2, radius, paint);
    canvas.drawCircle(x3, y3, radius, paint);
//    canvas.drawPoints(pts2, pointPaint);
    paint.setColor(Color.WHITE );;//
    canvas.drawCircle(x0, y00, radius, paint);
    canvas.drawCircle(x1, y11, radius, paint);
    canvas.drawCircle(x2, y22, radius, paint);
    canvas.drawCircle(x3, y33, radius, paint);
   
    float textWidth = 20.0f;
    float textHeight1 = 10.0f*screenHeight/480.0f;
   
    textPaint.setTextSize(20.0f);//
    canvas.drawText(tempHigh[0]+"°", x0-textWidth/2, y0-textHeight1, textPaint);
    canvas.drawText(tempHigh[1]+"°", x1-textWidth/2, y1-textHeight1, textPaint);
    canvas.drawText(tempHigh[2]+"°", x2-textWidth/2, y2-textHeight1, textPaint);
    canvas.drawText(tempHigh[3]+"°", x3-textWidth/2, y3-textHeight1, textPaint);
   
    float textHeight2 = 25.0f;
   
    textPaint.setTextSize(20.0f);//
    canvas.drawText(tempLow[0]+"°", x0-textWidth/2, y00+textHeight2, textPaint);
    canvas.drawText(tempLow[1]+"°", x1-textWidth/2, y11+textHeight2, textPaint);
    canvas.drawText(tempLow[2]+"°", x2-textWidth/2, y22+textHeight2, textPaint);
    canvas.drawText(tempLow[3]+"°", x3-textWidth/2, y33+textHeight2, textPaint);
   
    float textWidth1 = 40.0f;
    textPaint.setTextSize(20.0f);
   
    if(screenHeight == 854){
    lowDis = 630f;highDis = 645f;
    }else if(screenHeight == 800){
    lowDis = 580f;highDis = 595f;
    }else if(screenHeight == 480){
    lowDis = 290f;highDis = 270f;
    }else if(screenHeight == 320){
    lowDis = 150f;highDis = 125f;
    }
    /*for (int i = 0; i < tempLow.length; i++) {
canvas.drawCircle(circleX + i*circleX, screenHeight - tempLow[i]*5 - lowDis, 2, paint);
canvas.drawText(tempLow[i]+"°", circleX + i*circleX, screenHeight - tempLow[i]*5-10 - lowDis, textPaint);
if(i < tempLow.length - 1){
canvas.drawLine(circleX + i*circleX,screenHeight - tempLow[i]*5 - lowDis, circleX + (i+1)*circleX, screenHeight - tempLow[i+1]*5 - lowDis, linePaint);
}
}
    for (int i = 0; i < tempHigh.length; i++) {
canvas.drawCircle(circleX + i*circleX, screenHeight - tempHigh[i]*5 - highDis, 2, paint);
canvas.drawText(tempHigh[i]+"°", circleX + i*circleX, screenHeight - tempHigh[i]*5-10 - highDis, textPaint);
                if(i < tempLow.length - 1){
canvas.drawLine(circleX + i*circleX,screenHeight - tempHigh[i]*5 - highDis, circleX + (i+1)*circleX, screenHeight - tempHigh[i+1]*5 - highDis, linePaint);
}
}*/
    }
    }
    private float[] sort(float[] data){
    for (int i = 1; i < data.length; i++) { // 数组有多长,轮数就有多长  
            // 将相邻两个数进行比较,较大的数往后冒泡  
            for (int j = 0; j < data.length - i; j++) {// 每一轮下来会将比较的次数减少  
                if (data[j] > data[j + 1]) {  
                    // 交换相邻两个数  
                    swap(data, j, j + 1);  
                }  
            }  
        }
return data;
    }
    private void swap(float[] data, int x, int y) {  
        float temp = data[x];  
        data[x] = data[y];  
        data[y] = temp;  
    }
}
===========================main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
     <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/ll">
       <TextView 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="绘图"
    /> 
    </LinearLayout>
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
     <SlidingDrawer android:id="@+id/slidingDrawerId"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:handle="@+id/handle"
                   android:content="@+id/content">
    <Button   
        android:id="@+id/handle"  
        android:layout_width="88dip"  
        android:layout_height="44dip"  
        android:background="@drawable/icon"  
        />   
    <LinearLayout   
        android:id="@+id/content"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"   >
    </LinearLayout>
   </SlidingDrawer>
</RelativeLayout>
最外层需要用RelativeLayout包裹

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

互联网 iis7站长之家