小编kar*_*e23的帖子

将InputStream转换为BufferedReader

我正在尝试使用Android中assets目录中的InputStream逐行读取文本文件.

我想将InputStream转换为BufferedReader以便能够使用readLine().

我有以下代码:

InputStream is;
is = myContext.getAssets().open ("file.txt");
BufferedReader br = new BufferedReader (is);
Run Code Online (Sandbox Code Playgroud)

第三行删除以下错误:

Multiple markers at this line
The constructor BufferedReader (InputStream) is undefinded.

我在C中尝试做的事情如下:

StreamReader file;
file = File.OpenText ("file.txt");

line = file.ReadLine();
line = file.ReadLine();
...
Run Code Online (Sandbox Code Playgroud)

我做错了什么或我应该怎么做?谢谢!

java android inputstream readline bufferedreader

143
推荐指数
3
解决办法
17万
查看次数

什么是Android/Java中的JavaScript setInterval/setTimeout?

任何人都能告诉我是否存在Android的setInterval/setTimeout的等价物?有人有任何关于如何做的例子吗?

javascript java android settimeout

113
推荐指数
8
解决办法
8万
查看次数

如何取消或停止NSThread?

我正在做一个应用程序,在读取XML文件时使用NSThread加载viewControllers的内容.

我做到如下:

-(void)viewDidAppear:(BOOL)animated
{
    // Some code...


    [NSThread detachNewThreadSelector:@selector(loadXML) toTarget:self withObject:nil];
    [super viewDidAppear:YES];
}

-(void)loadXML{

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    // Read XML, create objects...

    [pool release];
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果用户在加载NSThread时更改为另一个viewController,我不知道如何停止NSThread,这样做应用程序崩溃了.

我试图取消或退出NSThread如下,但没有成功:

-(void)viewsDidDisappear:(BOOL)animated{
    [NSThread cancel];
    // or [NSThread exit];
    [super viewDidDisappear:YES];
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?谢谢.

iphone sdk nsthread ios

6
推荐指数
1
解决办法
9117
查看次数

如何从iPhone sdk上的UIButton获取图像名称?

我试图从自定义按钮获取背景图像的名称.

当我点击UIButton时,我调用此方法:

-(void)getButtonImageName:(id)sender{       
    UIButton *resultButton = (UIButton *)sender;
    NSLog(@" The button's image is %@.", resultButton.currentImage);
}
Run Code Online (Sandbox Code Playgroud)

我可以从按钮获取标题和其他属性,但不能获取背景图像名称.

谁知道怎么做?谢谢!

iphone sdk uibutton

5
推荐指数
2
解决办法
2万
查看次数

(iPhone SDK)如何通过标签ID修改UIButton?

我创建了一组按钮,如下所示:

NSString *nameImg;
UIButton *button;

for(int i=1;i<=144;i++){
    button = [[UIButton alloc] initWithFrame:CGRectMake(posX, posY, 43, 43)];
    nameImg = [NSString stringWithFormat:@"img%i.png",i];
    [button setBackgroundImage:[UIImage imageNamed:nameImg] forState:(UIControlState)normal];
    button.tag = i;
    [scrollView addSubview:button];

    posX += 55;

    if (i % 4 == 0){
            posY += 55;
        posX = 15;
    }
}
Run Code Online (Sandbox Code Playgroud)

如何修改按标签获取的按钮?有可能做类似以下的行吗?

[button.tagId setTitle:@"hello"];
Run Code Online (Sandbox Code Playgroud)

我不想要一个监听器方法,我只想修改按标签识别它的按钮.

提前致谢

iphone uibutton

2
推荐指数
2
解决办法
2607
查看次数

在Android上使用自定义字体

我正在尝试加载自定义字体,如下所示:

private Paint customFont18;
customFont18 = new Paint();
customFont18.setTextSize(18);
Typeface fontFace = Typeface.createFromAsset(getAssets(), "FONT.TTF"); 
customFont18.setTypeface(fontFace);
Run Code Online (Sandbox Code Playgroud)

getAssets失败了,这个:

-The method getAssets() is undefined for the type MyClass
-assetManager cannot be resolved to a variable
Run Code Online (Sandbox Code Playgroud)

我的问题是什么?我见过几个这样的例子,但在我的情况下都没有.提前致谢.

java fonts android

2
推荐指数
1
解决办法
4676
查看次数

可以从传递String参数的资源中加载R.drawable吗?

可以从传递给R.drawable字符串的资源加载图像吗?

我正在尝试这个:

public static Bitmap LoadBitmap(Context context, String filename)
{
     Bitmap image;
     image = BitmapFactory.decodeResource(context.getResources(), R.drawable.filename);
     return image;
}
Run Code Online (Sandbox Code Playgroud)

引发以下错误:

filename cannot be resolved or is not a field
Run Code Online (Sandbox Code Playgroud)

我正在尝试在R文件中创建一个常量字段但是抛出以下行:

R.java was modified manually! Reverting to generated version!
Run Code Online (Sandbox Code Playgroud)

我将非常感谢您的帮助或建议.谢谢

java android bitmap

2
推荐指数
1
解决办法
6285
查看次数

返回UINavigationController的第一个索引?

我正在做一个使用UINavigationController的应用程序,我正在切换到其他UIViewControllers,如下所示:

if(self.myViewController == nil){
    MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
    self.myViewController = aViewController;
    [aViewController release];
}

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.myNavController pushViewController:myViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)

我想这是在UINavigationController中创建一堆UIViewControllers,也许是一个索引数组?我想知道怎么回头而不必一个接一个地回来.

例如,我正在通过几个屏幕航行,并且我想在第一个导航索引处返回一个按钮.我还想知道如何修改索引,查看,擦除以及与此问题有关的任何内容.

对不起,如果我没有解释清楚.

iphone sdk uinavigationcontroller ios

2
推荐指数
2
解决办法
6182
查看次数

在iPad上使用UIActionSheet的问题

我正在为iPhone和iPad制作一个兼容的应用程序,我在动作表中显示了一个选择器,如下所示:

actionSheet = [[UIActionSheet alloc] initWithTitle:@"Day / Month"
                                          delegate:self
                                 cancelButtonTitle:nil
                            destructiveButtonTitle:nil
                                 otherButtonTitles:nil];

picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,40,0,0)];
picker.delegate = self;
picker.showsSelectionIndicator = YES;
[actionSheet addSubview:picker];

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
[actionSheet setBounds:CGRectMake(0,0,320,469)];
Run Code Online (Sandbox Code Playgroud)

这适用于iPhone,但对于具有相同代码的iPad版本,除了那些不同尺寸的人给我以下错误:

*由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效的参数不满足:view!= nil'

在这一行:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
Run Code Online (Sandbox Code Playgroud)

我尝试过showInView:self.view,self.Window,self.view.superview但没有...

我想知道是什么给出了这个错误,并且不会让我以同样的方式这样做...提前感谢!

iphone uiactionsheet ipad ios

2
推荐指数
1
解决办法
3844
查看次数

使用jquery检查div是否内部有一个img元素

我正在使用图片的jquery拖放到目标div.

我有一个调用一个函数的按钮,该函数应检查图像是否在div中,但我无法使其正常工作.

我正在努力做如下:

<script>
    ....

    $( '#check' ).click(function(){
        if($("#droptarget:has(img.img1)")){
            alert("yes");
        }else{
            alert("no");
        }
    });
</script>

<img id="img1" class="img1" src="image.png">
<div id="droptarget"></div>
<a href="javascript:" id="check">check</a>
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题?

编辑:总是在第一个条件下进入警报("是")而没有div内的图像

jquery drag-and-drop jquery-ui

1
推荐指数
1
解决办法
7606
查看次数

如何在触摸屏时保留onTouchEvent?

当我触摸屏幕时,我有以下方法来处理:

public boolean onTouchEvent(MotionEvent event) {

    boolean touchDown = true;
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Log.i(TAG,"touching the screen: YES");
        case MotionEvent.ACTION_UP:
            touchDown = false;
            Log.i(TAG,"touching the screen: NO");
    }
    return touchDown;

}
Run Code Online (Sandbox Code Playgroud)

当我触摸屏幕而不移开手指时Logcat的结果是:

touching the screen: YES
touching the screen: NO
Run Code Online (Sandbox Code Playgroud)

直到我从屏幕上释放myfinger,我才想要显示第二个日志.

我做错了什么?

谢谢.

java android touch-event

0
推荐指数
1
解决办法
790
查看次数