Month: November 2012

心理学

最近对心理学很感兴趣,在豆瓣上看到了一些推荐入门书籍下载下来准备有空的时候看看,比如“图解心理学“,”真实的幸福“。

另外今天学到了几个心理学现象。感觉非常有意思。

1.悬索桥上的爱

2.登门槛效应

3.留面子效应

Advertisements

死了都没人知道吧

前天实验室一个今年来的新生师妹和我说,她感觉在美国这个地方,真的就像浮萍一样,有时候感觉死了也不会有人知道。当时我就心里一痛,这完全和我想的一样。当时我出于师兄的责任,安慰了一下师妹。

今天晚上睡不着。像黑夜一样深的寂寞又爬满了全身,像无孔不入的虫。脑袋里漫无目的的空转着,然后又想起了这句话。或许这其实和美国无关,只是当我们来到一个朋友更少亲人更少的地方的时候,这种感觉得到了放大而已。事实是,这个地球不会为任何一个人停止转动,可以预见的是如果你死去,周围绝大多数人生活也不会丝毫受到影响,他们只会停留片刻,,然后继续上路。你从小到大那样在乎身边的同学朋友们对你的看法,一直想着如何和他们打成一片,有时候也想着似乎如果没有你,他们的世界无法想像,你们的一个个所谓圈子怕是都要解散吧。可是,事实可能是,即使你死去,大多数人,还是像看路边的死狗一样,停留片刻,哀叹一声,和其他看客耳语一番,“它真可怜”,然后继续上路。

似乎人就是被造物主造的这样复杂。他从未离开过一个不断膨大的自我,却又无时无刻不在渴望着去接近旁人。他感到寂寞,却又固步自封。他自以为强大无比,却一个人在黑夜里写下这样悲伤的文字。

他在干嘛?

此时此刻,我看着自己在做的事情。不知道为什么感觉这么奇怪,好像自己的灵魂已经出窍,走出我的躯壳,然后反过来在看我的躯体在电脑前敲打着。这一刻,我做的事情有什么意义? 我调试一会程序,然后上网搜索一些解决方案,然后跑来写个心得文章,然后就突然灵魂出窍了,不知道”他“做这些是在为什么,为了怎样一个目标,会造成如何的影响。我也不知道”他“为什么此时此刻坐在这里,而不是其他地方,在更广大的世界里任何一个地方,比如荒山野岭,比如纽约繁华的街头,比如故乡的小路上。我不知道”他“到底是为了什么,在这一刻坐在了这个看上去很无聊的地方,他好像也就是机械的一样的坐着,”他“脑袋里到底在想些什么? 这种感觉是这样的诡异,就像我们经常看着一个很熟悉的常用汉字,就突然觉得陌生起来,不知道这个字到底有没有写对一样,然后就一直看到脑袋疼不愿去看为止。

android.content.res.ResourceNotFoundException:String resource ID #0x2 in onListItemClicked

final int row_index = participant.getColumnIndex(HRADbAdapter.participant_id);
final int participant_id = participant.getInt(row_index);

TextView participant_id_tv = (TextView )new_participant_view.findViewById(R.id.patient_id);
participant_id_tv.setText(participant_id);  //this is the line that caused the above exception.

At the beginning, I was thinking it’s because participant_id_tv is null. but after looking at my laoyout file, R.id.patient_id is clearly a valid resource id, with <TextView android:id=”@+id/patient_id”…./>

It turns out it’s because when I pass an integer to setText, android thinks I am passing a resource id and tries to find resource. what I need is to explicitly convert int to String as below:

participant_id_tv.setText(Integer.toString(participant_id));

Now it’s okay. simple.

learn how to detect Swipe left / right in android

First issue: horizontal swipe is not detected in ScrollView

I implemented onFling using below code:

public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
System.out.print(“onFling is called!\n”);
// return true;
try {
if (Math.abs(e1.getY() – e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() – e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//do your code
BackHandler((Button)findViewById(R.id.btn_back));
return true;
} else if (e2.getX() – e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
//left to right flip
ContinueHandler((Button)findViewById(R.id.btn_continue));
return true;
}
} catch (Exception e) {
// nothing
}
return false;
}

I used the code from a post on Stackoverflow( http://stackoverflow.com/questions/937313/android-basic-gesture-detection ). It says it’ll work. but when I put it into my project, I found only left swipe will be detected while right swipe can’t invoke any gesture listener method, including onFling, onTouchEvent, onDown.

But then I found out it’s because I used Scrollview in my layout file. If I remove the scrollview, then both left and right swipe will work. however, scrollview has to be in the layout, so what should I do? I found the solution is to override dispatchTouchEvent method of gestureListener  (http://stackoverflow.com/questions/8326599/horizontal-swipe-not-detected-in-scrollviews-parent)

@Override
public boolean dispatchTouchEvent( MotionEvent ev ) {
// TouchEvent dispatcher.
if( detector != null ) {
if( detector.onTouchEvent( ev ) )
// If the gestureDetector handles the event, a swipe has been
// executed and no more needs to be done.
return true;
}
return super.dispatchTouchEvent( ev );
}

Now swipe works in the presence of scrollview. however, i found another issue.

Problem 2: button & spinner can not be selected.

This problem doesn’t show up when the dispatchTouchEvent() method is not overrided as code above. so how to solve this problem? what I did is to change the last line  “return true” to “return false” in onDown, onTouchEvent and onScroll method in which “return true” is the default last (or only) line code in the method.

when I swipe, I found onDown is first called, then onScroll, last onFling. when nothing is done in those code, we should make them return false. Returning true “means” that the event has been consumed, and is therefore not passed on.

if the event is dealt in the current method, then return true, meaning the event is consumed, so no need to pass it on to child views;
Otherwise, return false so the event can be passed on to child views.

Testing android app on real Device

Today I got the Samsung Galaxy Note 10” tablet and can’t wait to install my uncompleted app on it.

First, I need to install USB driver for the tablet. When I plugged it in, it shows fail to find the android usb driver for ADB(Android Debug Bridge). At this time, my Eclipse can’t find the device, and neither abc. when I call “abc devices” command line, it shows no attached device.  For samsung tablet, I went to samsung website to install ADB driver. it turns out I have to install Kies from Samsung and this will install ADB driver for me. I couldn’t find independent ADB driver. Now, “adb devices” on command line will show a device connected. the number shown doesn’t make sense though. Note: on command line, first need to go to the folder of android-sdk/platform-tools/, then call adb devices.

Then, I turn the debugging mode on by Developer options->USB debugging mode

Now, in Eclipse, I run my application as usual, only to set “Run configuration”->Target->Launch on all compatible devices/avd->active devices.

Now the app is installed to the tablet.  As long as the cable is connected between the tablet and the computer, I can compile and run the app on tablet which is faster than when running on emulator. awesome!

However, I had an issue in this whole afternoon and evening. I keep running into “null pointer” error when I click on some of  elements in the questionnaire, or when I try to open an activity( in my case, questionnaire activity). and I thought maybe it’s because Samsung use different library . so I changed some elements name, or changed the way of implementing the style of spinner (set android:entries=”@array/**” instead dynamically customize it in onCreate(). all the errors are still there. they are all caused by findViewById() can’t find the element. and I couldn’t find a pattern for what elements may go wrong.  At first, i thought maybe it’s because I set some element to be android:visibility=”gone” in the xml file, and findViewById() can’t find it under Samsung library or what.

Guess what, it’s all because I created layout files of QuestionnaireActivity for different densities, but I didn’t update the version for xhdpi. I only update for mdpi (layout folder without any prefix).  But this tablet is xhdpi. thus, it is using the old layout file that doesn’t have all the elements.

who I will be in five years?

This is a popular behavior question in interviews. But recently I have been asking myself this question a lot. every time I need to kill my time, I will start thinking about this question. I definitely want to stay employed after five years. but what direction do I want my career be heading towards at that time? Or, what do I want most in my career?

Honestly, never really thought about this seriously before. Most of the time, I just follow the main stream and here I am now. lucky enough, I am in a not bad position at this time. After 1 year and a half confusing time in PH.D. program I decided to quit the PH.D. and get a master degree only. Now, there are 6 more months to get my master degree in computer science for which I didn’t pay a penny for, instead I actually made some bucks out of it; And I have one job offer in California at hand long before graduation. Yet when I look back, I realize how much different this is from what I pictured myself when I was a senior in college preparing for GRE and applying to US schools.

At the end of my college, I got two master offer with full support, and several other PHD offers. and I chose PHD offer. I still remember one school who gave me a master offer with fellowship, Fordham University. The professor who gave an interview to me was suggesting I should take the master offer for now, and later on I can decide if I still want to go PH.D. That’s the same suggestions I got from some other people I met on Internet. However, at that time, I thought I am determined to go for PH.D. if anyhow I will go to PH.D., why would I bother to get a master at first? Isn’t that a waste of time?

Now, I can’t help thinking about that decision I have made. It’s hard to see what’s gonna happen if a different road was taken. but it’s apparently these kind of decisions do have a big impact of our lives.

so I feel so confused about the future. it’s uncontrollable and can’t be planned. some one will tell me, “that’s why you need to follow your heart, so you will feel happy at least”. I would agree with this. but unfortunately I just cant tell what my heart is telling me to do. Even I hear something in my heart, I will think is this good? am I just finding excuses for not choosing the difficult path which more people like better? or do I really know that’s what I want? Or I will ask myself, is this difficult path worth it?

I will fall back, flinch, retreat. and so I don’t get to test what’s my heart telling me to do.