ラベル

ラベル 画面遷移 の投稿を表示しています。 すべての投稿を表示
ラベル 画面遷移 の投稿を表示しています。 すべての投稿を表示

2011年9月5日月曜日

ListViewの一行をクリックし、別の画面に遷移【android】【ListView】【画面遷移】

ListViewの一行をクリックし、別の画面に遷移する場合には、
onListItemClick()をオーバーライドします。
※別の方法もあるようですが、この方法が比較的綺麗にコーディングできそうです。

オーバーライドしたonListItemClick()の中で、intentインスタンスを作成し、
startActivity()を実行します。
Intent intent = new Intent(遷移元のクラス.this, 遷移先のクラス.class);
と作成してください。

Intent.putExtra()を使用することにより、値の受け渡しも可能です。

    /**

* クリックされたListに対して、ImageListViewに遷移する。
* (非 Javadoc)
* @see android.widget.AdapterView$OnItemClickListener#onItemClick(android.widget.AdapterView, android.view.View, int, long)
* @param AdapterView parent(未使用)
* @param View view(未使用)
* @param int position(クリックされたポジション)
* @param long id(未使用)
* @return void
* @exception なし
*/

@Override
public void onListItemClick(ListView listView, View v, int position,long id) {
super.onListItemClick(listView, v, position, id);

String dir = dirList.get(position);
Log.v("onClick", String.format("onListItemClick: %s", dir));

// ディレクトリリストからクリックされたディレクトリを取得
String imageDirPath = dirList.get(position);
// ImageListViewクラスに、ディレクトリを渡す為のIntentを作成
Intent intent = new Intent(DirListView.this, ImageGridView.class);
// Intentにクリックされたディレクトリを設定
intent.putExtra("IMAGE_DIR_PATH", imageDirPath);
// ImageListViewに遷移
startActivity(intent);
}

2011年9月4日日曜日

別パッケージのActivityに遷移【android】【画面遷移】【エラー】

前回の続きです。前回↓

⇒android.content.ActivityNotFoundException

別Activityに遷移する際、前回記載した
        </activity>

<activity android:name="ImageListView"></activity>


では同様のエラーとなり、Activityを見つけることができず、エラーとなってしまいます。
これは、AndroidManifest.xmlの 「「package="」は1つしか記述できないようですので、2つ目からはパッケージ込みで記述する必要があります。


上記をまとめると下記となります。

【現象】
別パッケージのActivityに遷移しようとするとエラーになる。

【LogCat】
…android.content.ActivityNotFoundException: Unable to find explicit activity class
※デバイス上でのログは、EclipseのDDMSのLogCatに表示されます。

【原因】
AndroidManifest.xmlに遷移先のアクティビティをパッケージ込みで記述していない為、
AndroidManifest.xmlに遷移先のアクティビティが設定されていないと判断されている。

【解決策】
AndroidManifest.xmlに遷移先のアクティビティを設定する。
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.co.vacaposi.android.iv.iv.iv0010"
android:versionCode="1"
android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DirListView"
android:label="@string/app_name">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="jp.co.vacaposi.android.iv.iv.iv0020.ImageGridView"></activity>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>

android.content.ActivityNotFoundException【android】【画面遷移】【エラー】

この投稿の続きがあります↓

⇒別パッケージのActivityに遷移【android】【画面遷移】【エラー】


デバイス上でのログは、EclipseのDDMSのLogCatに表示されます。

【現象】
画面遷移時に「…has stopped unexpectiedly. Please try again.」というダイアログが表示され、
アプリケーションが終了してしまう。

【LogCat】
…android.content.ActivityNotFoundException: Unable to find explicit activity class 
※デバイス上でのログは、EclipseのDDMSのLogCatに表示されます。

【原因】
AndroidManifest.xmlに遷移先のアクティビティが設定されていない。

【解決策】
AndroidManifest.xmlに遷移先のアクティビティを設定する。



        </activity>

<activity android:name="ImageListView"></activity>