【问题标题】:How to call spinner in tab Activity?如何在选项卡活动中调用微调器?
【发布时间】:2012-03-21 06:39:03
【问题描述】:

我想在选项卡活动中调用微调器。我已经这样做了,但它会产生这样的错误。

Error is 03-20 17:08:08.397: E/AndroidRuntime(347): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@405ee8b8 is not valid; is your activity running?

我的代码

        Cursor cursor = null;
    try{
    senderId=(Spinner)findViewById(R.id.spinner1);
    String[] emailAddress={};
    Uri uri=Uri.parse("content://com.android.email.provider/account");
    String[] projection={"emailAddress"};
    ArrayList<String> emailList=new ArrayList<String>();
    cursor=getContentResolver().query(uri, projection, null, null, null);
    cursor.moveToFirst();
    while(!cursor.isAfterLast())
    {
        emailList.add(cursor.getString(cursor.getColumnIndex("emailAddress")));
        cursor.moveToNext();
    }
    emailAddress = (String[]) emailList.toArray(new String[0]);
    @SuppressWarnings({ "unchecked", "rawtypes" })
    ArrayAdapter<CharSequence> adapterCountry=new ArrayAdapter(getParent(),android.R.layout.simple_spinner_item,emailAddress);
    adapterCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    senderId.setAdapter(adapterCountry);
    //senderId.setAdapter(new  ArrayAdapter<String>(mContext,android.R.layout.simple_spinner_item, emailAddress));
    }catch (Exception e) {
        // TODO: handle exception
    }
    finally{
        cursor.close();
    }

【问题讨论】:

  • 你能粘贴整个代码吗?

标签: java android android-layout android-intent android-ndk


【解决方案1】:

您在这里使用了错误的上下文,因此请尝试使用LayoutInflatersetContentView(view_inflated); 来扩展您的布局,如下所示,

View view = LayoutInflater.from(getParent()).inflate(R.layout.your_xml, null);
setContentView(view);
your_spinner = (Spinner)view.findViewById(R.id.your_spinner_id);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多