English 中文(简体)
如何根据用户选择开发一个 Spinner 来改变图像View 图像图像
原标题:how to develop a Spinner changing the image of ImageView according to the user selection

我试图开发一个能根据用户选择来改变图像查看图像图像的旋转器。 我成功地开发了类似以下代码的代码, 但我想问,是否有可能开发出一个能够更容易管理的方式。

我的想法是把它发展成这样的形式:

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

目前,我正面临一个问题:在浏览了几张图像之后,我正在面对一个脱离记忆的问题,你可否给我一些关于如何解决问题的建议?

最佳回答

我认为您应该使用 Hashmap , 因为它给了您 < strong > keey- value 双对功能, 以适应 < em> map name 及其 < em> 映像资源 的价值

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签