我正在使用Tabwidget,Tab以tutorial
中显示的相同方式实现“MainActivity - > Activity1 - > Activity2(给定图片)”
现在点击微调器给出了
android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44eb8748 is not valid; is your activity running?
我已经尝试了Android Spinner Error : android.view.WindowManager$BadTokenException: Unable to add window,但这对我没有帮助
我知道上下文存在错误,但我无法弄明白
听到我的意图,它开始DetailActivity
intent = new Intent(getParent(), DetailActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity)getParent();
parentActivity.startChildActivity("SelectActivity", intent);
我的代码DetailActivity
给出了吼叫
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.package_detail);
setUpViews();
id = getIntent().getExtras().getInt("WEBSITE_ID");
adapter = new KeywordAdapter(getApplicationContext(), id,
getLNApplication().getKeyworddetail());
listTags.setAdapter(adapter);
spinneAdapter = new SpinnerListAdapter();
spinnerList.setAdapter(spinneAdapter);
spinnerList.setSelection(id, true);
spinnerList
.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
// txtHeader.setText(getLNApplication().getWebsiteList()
// .get(position).getName());
adapter.forceReload();
adapter = new KeywordAdapter(DetailActivity.this,
position, getLNApplication().getKeyworddetail());
listTags.setAdapter(adapter);
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
SpinnerAdapter
public class SpinnerListAdapter extends BaseAdapter {
private List<ClientDetail> siteList;
public SpinnerListAdapter() {
siteList = getLNApplication().getWebsiteList();
}
public void forceReload() {
notifyDataSetChanged();
}
@Override
public int getCount() {
return siteList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return siteList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
// LayoutInflater inflater = (LayoutInflater) context
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// LayoutInflater inflater = getLayoutInflater();
// LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
view = inflater.inflate(R.layout.spinner_item_display, null);
TextView websiteName = (TextView) view.findViewById(R.id.spinnerItem);
if (siteList.get(position).getName() != null) {
websiteName.setText(siteList.get(position).getName());
websiteName.setTextColor(0xFF000000);
}
return view;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View view = convertView;
// LayoutInflater inflater = (LayoutInflater) context
// .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// LayoutInflater inflater = getLayoutInflater();
// LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
LayoutInflater inflater = LayoutInflater.from(DetailActivity.this.getParent());
view = inflater.inflate(R.layout.spinner_dropdown_display, null);
TextView websiteName = (TextView) view.findViewById(R.id.spinnerDropDownItem);
if (siteList.get(position).getName() != null) {
websiteName.setText(siteList.get(position).getName());
websiteName.setTextColor(0xFF000000);
}
return view;
}
}
我做错了吗?
请帮助我......非常感谢你
答案 0 :(得分:1)
答案 1 :(得分:1)
在Tab活动中,如果您要提供任何警告对话框,那么在这种情况下,您已设置标签活动的上下文&amp;不是当前的活动对象。
而不是
adapter = new KeywordAdapter(getApplicationContext(),id,getLNApplication().getKeyworddetail());
listTags.setAdapter(adapter);
使用以下
adapter = new KeywordAdapter(Tabs.ctx,id,getLNApplication().getKeyworddetail());
listTags.setAdapter(adapter);
其中Tabs.ctx是标签活动的上下文&amp;那是静态变量。
答案 2 :(得分:0)
在TabWidget
中也使用此代码,您可以解决此错误
View view = LayoutInflater.from(this.getParent()).inflate(R.layout.package_detail, null);
this.setContentView(view);