English 中文(简体)
pin子如何知道其价值?
原标题:How does a spinner know its value?

我有一个支柱,开始开展第二次价值变化活动。 这种做法是好的。

返回后,一切工作都得当。 但是,如果现在我轮值流动,那么奥特温斯当选的利比亚人就被打! 原因? 关键应放在第1位。 什么意味着不会打回。

How does android know which spinner item is selected? I tried to prevend to restore this information by sending the base class the a null value for the savedInstanceState.

这里有一些法典:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
    setContentView(R.layout.menu);
    String db=MyDatabase.getData();

    if(db == null)
        db="";
    Spinner spinner=(Spinner)findViewById(R.id.spinner);
    MyAdapter adapter=new MyAdapter(this, db, "ID", "Name");
    spinner.setAdapter(adapter);
    adapter.setHint(spinner, "Please select...");
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id2) {
            int id=((SpinnerItem)parent.getAdapter().getItem(position)).getId();
            Intent intent=new Intent();
            intent.setClass(MainMenu.this, Other.class);
            intent.putExtra("id", id);
            startActivity(intent);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
}

这里是我的适应者:

public class MyAdapter extends ArrayAdapter<SpinnerItem> {
    private final Context context;
    private String hint;

    public MyAdapter(Context context, String input, String key, String value) {
        super(context, android.R.layout.simple_spinner_item, create(input, key, value));
        this.context=context;
    }

    private static SpinnerItem[] create(String input, String key, String value) {
        Vector<SpinnerItem> list=new Vector<SpinnerItem>();
        // fill the list
        return list.toArray(new SpinnerItem[] {});
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // show the hint
        if(position == -1) {
            TextView tv=new TextView(context);
            tv.setTextColor(Color.DKGRAY);
            tv.setText(hint);
            return tv;
        }
        return super.getView(position, convertView, parent);
    }

    public void setHint(Spinner spinner, String hint) {
        if(spinner.getAdapter() == null) {
            throw new IllegalStateException("Set your adapter first!");
        }
        this.hint=hint;
        try {
            final Method m=AdapterView.class.getDeclaredMethod("setNextSelectedPositionInt", int.class);
            m.setAccessible(true);
            m.invoke(spinner, -1);

            final Method n=AdapterView.class.getDeclaredMethod("setSelectedPositionInt", int.class);
            n.setAccessible(true);
            n.invoke(spinner, -1);
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
    }
}
最佳回答

当您轮流使用你的装置时 活动重新启动或重新调整后,将这一条线添加到你在活动标本中最著名的档案中,以避免。

android:configChanges="keyboardHidden|orientation"
问题回答

您<>改为 活动编号onCreate(>> 。

byfall,作为主人的行为,onItemS selectedListener()在活动开始时被称作“”。

www.un.org/Depts/DGACM/index_spanish.htm 因此,就本案而言,这就是:。

这些问题的解决办法见:。 问 题 <代码>checkBoxCounter andeckBoxInitialized,并试图在你的案件中实施同样的规定。





相关问题
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 ...

热门标签