だから私は検索して検索しましたが、私が探しているようなものは何も見つかりませんでした. いくつかの ListActivities があり、1 つをクリックして次のリストや次のリストなどに移動できます。適切なリスト項目をクリックすると、res フォルダーから画像が表示されます。私は午後中ずっとこれに行き詰まっていて、私が見つけることができるものは何も機能していません. どんな助けでも素晴らしいでしょう。例 CoverSheet を選択すると、cover_sheet.png を取得します。ありがとうジェームズ
アプリケーションのエントリ ポイント:Menu.java
public class Menu extends ListActivity
{
public static final String EXTRA_PICTURE = "extra.picture.toshow";
String classes[] = { "CoverSheet",// "TreatmentProtocols", "EMSProcedures",
// "DrugList", "EMSPolicies", "EMSTriageAndDestinationPlan",
// "Appendices"
};
//in this array you store the drawable resource ids to show.
//you can change it to hold urls or other identifiers.
int images[] = { R.drawable.cover_sheet, };
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,
android.R.layout.simple_list_item_1, classes));
}
protected void onCreate1(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.imageview);
final int imgResource = getIntent().getIntExtra(Menu.EXTRA_PICTURE, 0);
final ImageView img = (ImageView)findViewById(R.id.img);
img.setImageResource(imgResource); }
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
String Menu = classes[position];
try
{
Class firstClass = Class.forName("protocols.NashCounty." + Menu);
Intent firstIntent = new Intent(Menu.this, firstClass);
firstIntent.putExtra(EXTRA_PICTURE, images[position]);
startActivity(firstIntent);
}
catch (ClassNotFoundException e)
{
Log.e("SAMPLE", "ClassNotFoundException ", e);
}
catch (Exception e)
{
Log.e("SAMPLE", "Exception ", e);
}
}
}
これは私が作成した私のクラスです
public class CoverSheet extends ListActivity
{
public static final String EXTRA_PICTURE = "extra.picture.toshow";
String classes[] = { "CoverSheet", };
// in this array you store the drawable resource ids to show.
// you can change it to hold urls or other identifiers.
int images[] = { R.drawable.cover_sheet };
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.imageview);
final int imgResource = getIntent().getIntExtra(
CoverSheet.EXTRA_PICTURE, 0);
final ImageView img = (ImageView) findViewById(R.id.img);
img.setImageResource(imgResource);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
String coversheet = classes[position];
try
{
Class firstClass = Class.forName("protocols.NashCounty."+classes);
Intent firstIntent = new Intent(CoverSheet.this, firstClass);
firstIntent.putExtra(EXTRA_PICTURE, images[position]);
startActivity(firstIntent);
}
catch (ClassNotFoundException e)
{
Log.e("SAMPLE", "ClassNotFoundException ", e);
}
catch (Exception e)
{
Log.e("SAMPLE", "Exception ", e);
}
}
}
以下は、imageviewという名前の私のxmlレイアウトです
<?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">
<ImageView android:id="@+id/img"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/cover_sheet" />
</LinearLayout>
以下は私のミニフェストです
<activity android:name=".activity.CoverSheet"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
</application>
</manifest>
私はあなたが以前言っていたことを誤解していました.
以下は、コードを実行しようとしたときの logcat エラーです。
05-18 17:15:26.221: E/AndroidRuntime(618): 致命的な例外: メイン 05-18 17:15:26.221: E/AndroidRuntime(618): java.lang.ArrayIndexOutOfBoundsException: length=1; index=3 05-18 17:15:26.221: E/AndroidRuntime(618): プロトコルで.NashCounty.Menu.onListItemClick(Menu.java:40) 05-18 17:15:26.221: E/AndroidRuntime(618): android.app.ListActivity$2.onItemClick(ListActivity.java:319) 05-18 17:15:26.221: E/AndroidRuntime(618): android.widget.AdapterView.performItemClick(AdapterView.java:292) 05-18 17:15:26.221: E/AndroidRuntime(618): android.widget.AbsListView.performItemClick(AbsListView.java:1058) 05-18 17:15:26.221: E/AndroidRuntime(618): android.widget.AbsListView で$PerformClick.run(AbsListView.java:2514) 05-18 17:15:26.221: E/AndroidRuntime(618): android.widget.AbsListView$1.run(AbsListView.java:3168) 05-18 17:15: 26.221: