我正在尝试阅读一些文字文件中的一些单词,我想用于我正在写的文字游戏.此列表存储在assets目录中,是一个txt文件.但是,每当我尝试打开它时,它都会引发异常.
List<String>wordList = new ArrayList<String>();
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(getAssets().open("wordlist.txt"))); //throwing a FileNotFoundException?
String word;
while((word=br.readLine()) != null)
wordList.add(word); //break txt file into different words, add to wordList
}
catch(IOException e) {
e.printStackTrace();
}
finally {
try {
br.close(); //stop reading
}
catch(IOException ex) {
ex.printStackTrace();
}
}
String[]words = new String[wordList.size()];
wordList.toArray(words); //make array of wordList
for(int i=0;i<words.length; i++)
Log.i("Brian", words[i]); //print out words in array
}
Run Code Online (Sandbox Code Playgroud)
这是错误日志,如果有任何帮助:
02-22 20:49:47.646: WARN/System.err(2351): java.io.FileNotFoundException: wordlist.txt …Run Code Online (Sandbox Code Playgroud) 我正在编写一个Android应用程序,我想在主屏幕上放置一个对话框或视图,以便用户可以输入文本而无需跳转到我的完整应用程序.我似乎无法让这个工作.如果我提出一个对话框(即使在透明活动中),我的应用程序也会启动.
如果您不知道我在说什么,请查看Facebook小部件.我想复制一个类似的行为来点击"你在想什么?" 框.
在此先感谢您的帮助!
布赖恩
我在onreceive方法中响应我的appwidget上的按钮按下.当我按下按钮时,我想强制小部件调用onupdate方法.我该如何做到这一点?
提前致谢!
我有一个(希望)一个相对简单的问题.如何告诉Android哪个布局用于纵向以及哪个布局用于我的AppWidget上的横向?
提前致谢!
我正在尝试获取EditText的字符数.我查看了EditText和TextView类的不同属性,但似乎没有返回字符数的函数.我曾尝试使用TextWatcher,但这并不理想,因为有时我会从首选项中将已保存的消息加载到EditText中,而TextWatcher不计算当时未键入的字符.
任何帮助都会很棒!
干杯!
我只是在几秒钟的延迟后尝试关闭一个NSPanel,但我无法启动我的NSTimer.如果我明确地在它上面调用fire方法,它会触发,但它永远不会自行解决.这是我的代码:
- (void)startRemoveProgressTimer:(NSNotification *)notification {
NSLog(@"timer should start");
timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(removeProgress:) userInfo:nil repeats:NO];
}
- (void)removeProgress:(NSTimer *)timer {
[progressPanel close];
}
Run Code Online (Sandbox Code Playgroud)
我的代码中确实有一些线程.我认为这是弄乱我的计时器的原因.
-(void)incomingTextUpdateThread:(NSThread*)parentThread {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//mark the thread as running
readThreadRunning = TRUE;
const int BUFFER_SIZE = 100;
char byte_buffer[BUFFER_SIZE]; //buffer for holding incoming data
int numBytes = 0; //number of bytes read
NSString *text; //incoming text from the serial port
[NSThread setThreadPriority:1.0];
//this will loop until the serial port closes
while …Run Code Online (Sandbox Code Playgroud) 我想做一件非常简单的事情.我在我的应用程序中有一个listview,我动态添加文本.但是,在某一点之后,我想改变listview中文本的颜色.因此,我创建了一个定义自定义列表项的XML,并将ArrayAdapter子类化.但是,每当我在自定义ArrayAdapter上调用add()方法时,项目就会添加到列表视图中,但文本不会放入其中.
这是我的XML:`
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_content" android:textSize="8pt"
android:gravity="center" android:layout_margin="4dip"
android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#FF00FF00"/>
Run Code Online (Sandbox Code Playgroud)
而我的ArrayAdapter子类:
private class customAdapter extends ArrayAdapter<String> {
public View v;
public customAdapter(Context context){
super(context, R.layout.gamelistitem);
}
@Override
public View getView(int pos, View convertView, ViewGroup parent){
this.v = convertView;
if(v==null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=vi.inflate(R.layout.gamelistitem, null);
}
if(timeLeft!=0) {
TextView tv = (TextView)v.findViewById(R.id.list_content);
//tv.setText(str[pos]);
tv.setTextColor(Color.GREEN);
}
else {
TextView tv = (TextView)v.findViewById(R.id.list_content);
//tv.setText(str[pos]);
tv.setTextColor(Color.RED);
}
return v;
}
}
Run Code Online (Sandbox Code Playgroud)
我确定我做的事情非常糟糕,但我对Android仍然有点新鲜.
谢谢!`
我似乎无法从AppWidgetProvider类中读取首选项.我的代码在Activity中工作,但它不在AppWidgetProvider中.这是我用来回读布尔值的代码:
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean autoreplyon = settings.getBoolean("autoreplyon", false);
Run Code Online (Sandbox Code Playgroud)
但是,我得到"方法getSharedPreferences(String,int)未定义类型小部件"错误(小部件是我的AppWidgetProvider类的名称).
在此先感谢您的任何建议!
大家好,
我刚刚开始为Android开发.我正在寻找移植我的一个iPhone应用程序,但我有点不知道如何在运行时绘制一个视图(一个未在XML中声明的视图).基本上,我想画一个简单的矩形,但之后能够在绘制后操纵它的框架.
很抱歉,如果这是一个非常非常简单的问题,但我似乎无法在这里找到一些与iPhone SDK相同的内容.
提前致谢!
我拼命地试图让我的头脑如何实现主屏幕小部件.现在,我(终于)能够在我的小部件上获得一个按钮,响应按钮按下在清单中设置一个意图过滤器.
但是,我不能为我的生活找出按下按钮时如何启动活动.基本上,这是我的代码:
@Override
public void onReceive(Context context, Intent intent)
{
super.onReceive(context, intent);
if(intent.getAction().equals("com.bic.search.searchWidget.CLICK"))
{
Toast.makeText(context, "It works!!", Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我真正想做的是开始一项新活动,而不是显示一个祝酒词.我知道它与未决意图有关,但我无法弄清楚如何让它工作.
任何帮助和示例代码将不胜感激.非常感谢谁回答这个问题!