私のアプリでは、カスタムリスナーのリストビューがあります。android - actvityは正しいですか?カスタムリスナーからの位置取得
私のアクティビティでonSaveInstanceStateとonRestoreInstanceStateを使用したいと思いますが、必要な情報は、クラスCustomListener内のメソッドOnItemClickです。
クリックされた項目のリストの位置を知る唯一の方法であるため、4つのonItemClickのパラメータの1つであるパラメータ "position"の値が必要です。そして、2つのmthods onSaveInstanceStateとonRestoreInstanceStateでは、アクティビティの状態を正しく復元する必要があります。 (私が行うには正しい方法ではないと思う方法を取得し、CustomListenerに設定し、2つの方法がonSaveInstanceStateとonRestoreInstanceStateある活動、それらを使用し作成する(ベストプラクティスがある)正しい - 1:
私の質問は2つですこれは私が他のアイデアを持っていない) 2 - 一度私はパラメータの位置を持っている、私はポートレートモードで私は横モード、システムに渡すため、CustomListenerのメソッドOnItemClick内にこのパラメータを設定する問題があるOnItemClickを呼び出さないため、メソッド内のパラメータは変更されず、ランドスケープレイアウトも変更されません。
この方法はMainActivityである:
private void populate(ListView lv){
ImageAdapter arrayAdapter;
//set list view
arrayAdapter = new ImageAdapter(this, R.layout.list_view_layout, arrayFromNumberToId, hmFromIdToName);
lv.setAdapter(arrayAdapter);
//set list listener
listener=new CustomListener(hm, hmFromIdToName, arrayFromNumberToId);
lv.setOnItemClickListener(listener);
}
このメソッドは、クラスCustomListenerである:あなたの答えFOR
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int imageID;
String description;
String name;
imageID = arrayFromNumberToId[position];
description = hm.get(imageID);
name = hmIdToName.get(arrayFromNumberToId[position]);
extras = new Bundle();
extras.putInt("imageID", imageID);
extras.putCharSequence("description", description);
extras.putCharSequence("name", name);
if(parent.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
Intent intent = new Intent(parent.getContext(), DescriptionActivity.class);
intent.putExtras(extras);
parent.getContext().startActivity(intent);
}
else{
ImageView imageViewLayout;
TextView textView;
textView = (TextView) parent.getRootView().findViewById(R.id.textDescription);
textView.setText(description);
imageViewLayout = (ImageView) parent.getRootView().findViewById(R.id.imageBig);
imageViewLayout.setImageResource(imageID);
textView = (TextView) parent.getRootView().findViewById(R.id.textName);
textView.setText(name);
textView.setTypeface(null, Typeface.BOLD);
}
}
THANKS !!!
お返事ありがとうございました。 – soissy