我正在尝试使用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)
我做错了什么或我应该怎么做?谢谢!
任何人都能告诉我是否存在Android的setInterval/setTimeout的等价物?有人有任何关于如何做的例子吗?
我正在做一个应用程序,在读取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)
有人可以帮忙吗?谢谢.
我试图从自定义按钮获取背景图像的名称.
当我点击UIButton时,我调用此方法:
-(void)getButtonImageName:(id)sender{
UIButton *resultButton = (UIButton *)sender;
NSLog(@" The button's image is %@.", resultButton.currentImage);
}
Run Code Online (Sandbox Code Playgroud)
我可以从按钮获取标题和其他属性,但不能获取背景图像名称.
谁知道怎么做?谢谢!
我创建了一组按钮,如下所示:
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)
我不想要一个监听器方法,我只想修改按标签识别它的按钮.
提前致谢
我正在尝试加载自定义字体,如下所示:
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)
我的问题是什么?我见过几个这样的例子,但在我的情况下都没有.提前致谢.
可以从传递给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)
我将非常感谢您的帮助或建议.谢谢
我正在做一个使用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和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但没有...
我想知道是什么给出了这个错误,并且不会让我以同样的方式这样做...提前感谢!
我正在使用图片的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内的图像
当我触摸屏幕时,我有以下方法来处理:
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,我才想要显示第二个日志.
我做错了什么?
谢谢.
android ×5
iphone ×5
java ×5
ios ×3
sdk ×3
uibutton ×2
bitmap ×1
fonts ×1
inputstream ×1
ipad ×1
javascript ×1
jquery ×1
jquery-ui ×1
nsthread ×1
readline ×1
settimeout ×1
touch-event ×1