2012년 8월 14일 화요일

TextView에서 A tag(HTML)로 Activity 실행


TextView test = new TextView(getApplicationContext());

test .setText(Html.fromHtml("this is a <a href='http://www.google.com/'>test</a>"));
test .setMovementMethod(LinkMovementMethod.getInstance());

위과 같이 코드를 작성하면 test 글자에 링크가 걸리고, 누르면 웹 브라우져를 띄운다.

AndroidManifest.xml에서 다음과 같이 선언하고

<activity android:name="com.test.link.TestActivity">
    <intent-filter >
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="test"/>
    </intent-filter>
</activity>


test .setText(Html.fromHtml("this is a <a href='test://test01/'>test</a>"));

로 코드를 수정하면

TestActivity가 수행되고, intent의 uri로 "test://test01/" 문자열이 날아간다.



PopupWindow 설정


외부 터치하면 자동으로 사라지는 팝업 윈도우 설정

PopupWindow pw = new PopupWindow(spv, drawWidth, drawHeight, true);

//아래의 방법대로 하면 팝업이 뜬 상태에서 다른 객체의 터치도 먹는다.
pw.setTouchable(true); // 터치 가능
pw.setOutsideTouchable(true); // 외부 터치 가능
pw.setBackgroundDrawable(new BitmapDrawable()); // 터치이벤트를 받도록 다시 그려준다.

ADT 업데이트 후 외부 jar 참조 에러

외부 JAR 첨부 후 ClassNotFoundError 이 발생했을 때 (ADT 16 이상)

lib 폴더를 libs 폴더로 바꿔주면 해결

ListView getView() 다중 호출

설계상의 문제인지는 모르겠는데 2번, 3번 중복해서 호출될 때가 있다.

그럴 때는 ListView의 Height을 wrap_content 가 아닌 fill_parent ( 또는 match_parent )로 바꿔주고

ListView를 감싸고 있는 Layout도 Height을 fill_parent ( 또는 match_parent ) 로 주면 해결된다.



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFFFF"
    android:orientation="vertical" >
 
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#ffffff"
  android:listSelector="#00000000"
  android:divider="#00000000"
  android:cacheColorHint="#00000000" />

</LinearLayout>