我试图开发一个能根据用户选择来改变图像查看图像图像的旋转器。 我成功地开发了类似以下代码的代码, 但我想问,是否有可能开发出一个能够更容易管理的方式。
我的想法是把它发展成这样的形式:
HK_map,R.drawable.map_101
UK_map,R.drawable.map_102
US_map,R.drawable.map_103
需要我使用hashmap 或阵列列表吗? 您能帮助我一些关于如何改进的建议吗? 许多提前感谢 。
My current Code[Updated]
package tool.mobile;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
public class SpinnerActivity extends Activity implements OnItemSelectedListener{
private ImageView view2;
private Spinner spinner2;
private ArrayAdapter adapter2;
private List<HashMap<String, String>> items;
private Bitmap snoop;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bible_help_1);
spinner2 = (Spinner) findViewById(R.id.spinner1);
view2 = (ImageView) findViewById(R.id.imageView1);
items = fillMaps();
SimpleAdapter adapter=new SimpleAdapter(this,items,R.layout.bible_help_spinner,
new String[]{"name"},
new int[]{R.id.title});
spinner2.setAdapter(adapter);
spinner2.setOnItemSelectedListener(this);
spinner2.setVisibility(View.VISIBLE);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
HashMap map = (HashMap)items.get(arg2);
String Drawing_1= map.get("Drawing").toString();
int resID = getResources().getIdentifier(Drawing_1, "raw", "tool.mobile");
Bitmap snoop= BitmapFactory.decodeStream(getResources().openRawResource(resID));
imageshow.setImageBitmap(snoop);
imageshow.setTag(resID);
imageshow.setTag(resID);
}
public void onNothingSelected(AdapterView<?> arg0) {
}
private List<HashMap<String, String>> fillMaps()
{
List<HashMap<String, String>> items = new ArrayList<HashMap<String,String>>();
HashMap<String,String> i = new HashMap<String,String>();
i.put("name","HK_map");
i.put("Drawing", "map_101");
items.add(i);
i = new HashMap<String,String>();
i.put("name","US_map");
i.put("Drawing", "map_102");
items.add(i);
return items;}
}
Current Problem
目前,我正面临一个问题:在浏览了几张图像之后,我正在面对一个脱离记忆的问题,你可否给我一些关于如何解决问题的建议?