なんかよく忘れる!
HogeHoge hoge = new HogeHoge(this) {
@Override
public void onSuccess() {
// Toast
}
};
なんかよく忘れる!
HogeHoge hoge = new HogeHoge(this) {
@Override
public void onSuccess() {
// Toast
}
};
以下、基本的なコード
public class MapInfoActivity extends Activity{
WebView webview;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// WebViewインスタンスを生成
webview = new WebView(this);
// setContentViewに作成したWebviewを設定する
setContentView(webview);
webview.setWebViewClient(new WebViewClient() {});
webview.getSettings().setJavaScriptEnabled(true);
// HTML5 では、localStrage を有効にする必要がある
webview.getSettings().setDomStorageEnabled(true);
webview.loadUrl( "file:///mnt/sdcard/index.html" );
}
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
/* 戻るボタン */
if (webview.canGoBack()){
webview.goBack();
} else {
finish();
}
return true;
}
return super.onKeyDown(keyCode, event);
}
}
manifest
<uses-permission android:name="android.permission.INTERNET" />
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
上のエラーがでた、でもカーソルの項目は1以上
結論、レコードが0件だった!
項目にアクセスする前に件数確認
c = db.query("T_IMAGE_STORY",
new String[] { "ID" },
"CATEGORY_ID = ? AND POS = ?",
new String[] { String.valueOf(categoryId), String.valueOf(pos) },
null,
null, "ID");
if(( c != null ) && c.getCount() > 0 ) {
c.moveToFirst();
id = c.getSting( 0 );
commons-lang download
解凍して適当なフォルダーに保存
プロジェクに jarファイル 追加
import org.apache.commons.lang3.StringUtils;
StringUtils.leftPad("12345",10,'0')
0000012345 になる
そのた使えるユーテリィ多数
<TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="TextView" android:textSize="20sp" android:ellipsize="end" android:scrollHorizontally="true" android:singleLine="true" />
上記で長い文字の時の行末が ”…” となる。
<ImageButton
android:id="@+id/button_hoge_hoge"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="@null"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:src="@drawable/hoge_hoge"
/>
上記の設定で height に合わせた高さにしてくれる。
まちがって background に画像を設定してはまった (^^)
package name “jp.hotaka.test”
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- name : custom view class name -->
<declare-styleable name="HogeStyle">
<attr format="string" name="hogeType" />
</declare-styleable>
</resources>
Preference の xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Hoge="http://schemas.android.com/apk/res/jp.hotaka.test" >
<jp.hotaka.test.HogePreference
hogeStyle:hogeType="hogehoge"
android:layout="@layout/hoge"
android:summary="summary"
android:title="title"
/>
HogePreference.java
package jp.hotaka.test;
class HogePreference extends Preference {
public HogePreference(Context context) {
super(context);
mContext = context;
}
public HogePreference (Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray tArray = context.obtainStyledAttributes(attrs,
R.styleable.HogeStyle);
String hoge = tArray.getString(R.styleable.HogeStyle_hogeType);
}
@Override
protected void onBindView(View view) {
super.onBindView(view);
// mTextView= (TextView)view.findViewById(R.id.hoge);
}
}
だいぶ hoge hoge しました。
以上、自分の作ったXMLで定義した画面を使って、好きなように画面を変える
ListView で ボタンなどを配置すると onClick イベントが発生して、 onItemClick が呼ばれずに position どうすんだ?
って時に
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
/* だいぶ省略 */
button = (Button) convertView.findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v){
((ListView) parent).performItemClick(v, position, (long)v.getId());
}
});
return convertView;
}
逆に ListView を一つにしたい時は、レイアウトに以下を設定
android:descendantFocusability="blocksDescendants"
android:descendantFocusability=”blocksDescendants”
10-12 11:09:48.240: W/ActivityThread(5846): Application hoge is waiting for the debugger on port 8100…
がでたまま
Attempting to connect debugger to ‘hoge’ on port 8600
[2012-10-12 11:09:39 – hoge] Launch error: リモート VM に接続できませんでした。接続がタイムアウトしました。
なんてのが出る。
なぜか DDMS 繋がらず…
誰かがなぜかポートを掴んでいる。
コマンドプロンプトで
netstat -oan | more
やっぱりだれかが掴んでいる。
プロセスIDは分かったが犯人特定できず…
まっ、いっか
eclipse ウィンドウ->設定->Android->DDMS->ベース・ローカル・デバッガー・ポート
8600->8601 へ変更
eclipse 再起動
とりあえずつながったよ。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="25"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="50"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="25"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
layout_weight で比率を指定する。
layout_height=”0dp” で指定することが大事