I am using the following code. When I change the orientation from portrait to landscape, and then back to portrait. it throws an Exception "not bound to the window manager." How to solve this problem. thank.
public class Search_List_Activity extends Activity{
public static String keyword=null, category_get_id;
public static ArrayList<String> type= new ArrayList<String>();
public static ArrayList<String> title= new ArrayList<String>();
public static ArrayList<String> des= new ArrayList<String>();
public static ArrayList<String> manu= new ArrayList<String>();
public static ArrayList<String> urls= new ArrayList<String>();
public static ArrayList<String> image_sm= new ArrayList<String>();
public static ArrayList<String> image_me= new ArrayList<String>();
public static ArrayList<String> image_la= new ArrayList<String>();
public static ArrayList<String> image_ex= new ArrayList<String>();
public static ArrayList<String> rel= new ArrayList<String>();
public static ArrayList<String> id= new ArrayList<String>();
public static ArrayList<String> cat_id= new ArrayList<String>();
public static ArrayList<String> min_price= new ArrayList<String>();
public static ArrayList<String> max_price= new ArrayList<String>();
public static ArrayList<String> stores= new ArrayList<String>();
public static ArrayList<String> offer_sku = new ArrayList<String>();
public static ArrayList<String> offer_detailurl = new ArrayList<String>();
public static ArrayList<String> offer_price = new ArrayList<String>();
public static ArrayList<String> offer_ori_price = new ArrayList<String>();
public static ArrayList<String> offer_markdownperct = new ArrayList<String>();
public static ArrayList<String> offer_shipcost = new ArrayList<String>();
public static ArrayList<String> offer_tax = new ArrayList<String>();
public static ArrayList<String> offer_total_price = new ArrayList<String>();
public static ArrayList<String> offer_bidded = new ArrayList<String>();
public static ArrayList<String> offer_merchant_prod_id = new ArrayList<String>();
public static ArrayList<String> offer_merchant_name = new ArrayList<String>();
public static ArrayList<String> offer_merchant_rating_img = new ArrayList<String>();
public static ArrayList<String> offer_merchant_logo = new ArrayList<String>();
public static ArrayList<String> offer_condition = new ArrayList<String>();
public static ArrayList<String> offer_stock = new ArrayList<String>();
public static ArrayList<String> offer_ship_amt = new ArrayList<String>();
public static ArrayList<String> offer_ship_type = new ArrayList<String>();
public static ArrayList<String> offer_id = new ArrayList<String>();
public static ArrayList<String> offer_cat_id = new ArrayList<String>();
public static ArrayList<String> offer_merchant_id = new ArrayList<String>();
public static ArrayList<String> category_id = new ArrayList<String>();
public static ArrayList<String> category_name = new ArrayList<String>();
public static ArrayList<String> offer_rating = new ArrayList<String>();
public static ArrayList<HashMap<String, Object>> mylist;
public static URL url1, url2;
public static JSONObject price;
public static String prod_type;
public static Boolean type_po;
public static Bitmap bmp;
public static String prod_id;
public static Boolean cat_flag;
static final int CATEGORIES_PRODUCE_ID = 0;
Dialog dialog_category;
Bundle bundle;
SQLiteDatabase db;
private String lv_arr[]={"Cell Phone Cases","NCAA Shop","MLB Shop","NBA Shop","NFL Shop","MP3 Player Cases and Skins","iPhone Cases and Skins"};
public static Boolean flag=true;
Boolean flagValue = true;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
System.out.println("Width:"+width);
System.out.println("Height:"+height);
if(width==600 && height==1024)
{
setContentView(R.layout.search_catagories);
System.out.println("HIiiiiiiiiiiiiii");
}
else{
flag = false;
setContentView(R.layout.search_categories_ls);
}
arraylists_clear();
TextView txt_search = (TextView)findViewById(R.id.editText1);
if(flagValue){
if(SearchRefine.checkflag){
bundle = getIntent().getExtras();
keyword = bundle.getString("keyword");
}
image_sm.clear();
title.clear();
min_price.clear();
db = openOrCreateDatabase("recentsearches1.db",SQLiteDatabase.CREATE_IF_NECESSARY,null);
db.setVersion(1);
db.setLocale(Locale.getDefault());
db.setLockingEnabled(true);
final String DATA="create table if not exists new_searchtab1("+"id INTEGER PRIMARY KEY AUTOINCREMENT,"+"search TEXT UNIQUE);";
db.execSQL(DATA);
ContentValues values = new ContentValues();
values.put("search", keyword);
long id1 = db.insert("new_searchtab1", null, values);
db.close();
}
final ListView lv = (ListView)findViewById(R.id.search_listView);
final ProgressDialog dialog = ProgressDialog.show(this, "BIZRATE",
"Loading....", true);
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
lv.setAdapter(new EfficientAdapter(Search_List_Activity.this));
dialog.dismiss();
}
};
Thread checkUpdate = new Thread() {
public void run() {
SearchResult_Json.json_parsing();
handler.sendEmptyMessage(0);
}
};
checkUpdate.start();
ImageButton grid_view_btn = (ImageButton)findViewById(R.id.gridview_bttn);
Button categories_btn = (Button)findViewById(R.id.categories_bttn);
categories_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Category_Search_Json.Json_parsing();
showDialog(CATEGORIES_PRODUCE_ID);
}
});
Button btn_refine = (Button)findViewById(R.id.refine_bttn);
btn_refine.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(Search_List_Activity.this,SearchRefine.class);
intent.putExtra("keyword",keyword);
startActivity(intent);
}
});
grid_view_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(Search_List_Activity.this,Search_GridView_Activity.class);
intent.putExtra("keyword", bundle.getString("keyword"));
startActivity(intent);
}
});
txt_search.setText(keyword);
keyword = keyword.replaceAll(" ", "+");
System.out.println("The String:"+keyword);
lv.setBackgroundColor(Color.WHITE);
lv.setCacheColorHint(Color.WHITE);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,View view,int position,long idddd)
{
if(type.get(position).equals("OFFER"))
{
prod_id = offer_id.get(position);
Intent intent = new Intent(Search_List_Activity.this,Compare_Product_Activity.class);
intent.putExtra("productType", "SZOID");
startActivity(intent);
}
else
{
prod_id = offer_id.get(position);
Intent intent = new Intent(Search_List_Activity.this,Compare_Product_Activity.class);
intent.putExtra("productType", "SZPID");
startActivity(intent);
}
}
});
}
private void arraylists_clear() {
type.clear();
image_sm.clear();
title.clear();
min_price.clear();
des.clear();
manu.clear();
urls.clear();
image_me.clear();
image_la.clear();
image_ex.clear();
rel.clear();
id.clear();
cat_id.clear();
min_price.clear();
max_price.clear();
stores.clear();
offer_sku.clear();
offer_detailurl.clear();
offer_price.clear();
offer_ori_price.clear();
offer_markdownperct.clear();
offer_shipcost.clear();
offer_tax.clear();
offer_total_price.clear();
offer_bidded.clear();
offer_merchant_prod_id.clear();
offer_merchant_name.clear();
offer_merchant_rating_img.clear();
offer_merchant_logo.clear();
offer_condition.clear();
offer_stock.clear();
offer_ship_amt.clear();
offer_ship_type.clear();
offer_id.clear();
offer_cat_id.clear();
offer_merchant_id.clear();
category_id.clear();
category_name.clear();
offer_rating.clear();
}
public static class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return image_sm.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
try {
url1 = new URL(image_sm.get(position));
url2 = new URL(image_me.get(position));
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
if(flag){
bmp = BitmapFactory.decodeStream(url1.openConnection().getInputStream());
}
else{
bmp = BitmapFactory.decodeStream(url2.openConnection().getInputStream());
}
} catch (IOException e) {
e.printStackTrace();
}
if (convertView == null) {
if(flag){
convertView = mInflater.inflate( R.layout.search_catagory_row, null);
System.out.println("WITH PORTRAITTT");
}
else{
convertView = mInflater.inflate( R.layout.search_category_row_land, null);
System.out.println("WITH LANDSCAPEEE");
}
holder = new ViewHolder();
holder.text = (TextView) convertView
.findViewById(R.id.search_text);
holder.text2 = (TextView) convertView
.findViewById(R.id.text_view_2);
holder.img = (ImageView) convertView.findViewById(R.id.images);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(title.get(position));
holder.text2.setText(min_price.get(position));
holder.img.setImageBitmap(bmp);
final int pos = position;
return convertView;
}
static class ViewHolder {
TextView text;
TextView text2;
ImageView img;
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch(id) {
case CATEGORIES_PRODUCE_ID:
dialog_category = new Dialog(this);
dialog_category.setContentView(R.layout.category_dialog);
ListView category_list= (ListView)dialog_category.findViewById(R.id.list_cat);
category_list.setBackgroundColor(Color.WHITE);
category_list.setCacheColorHint(Color.WHITE);
category_list.setAdapter(new ArrayAdapter<String>(this,R.layout.cat_row, R.id.label , category_name));
category_list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,View view,int position,long idddd)
{
cat_flag=true;
SearchRefine.checkflag=false;
Intent intent = new Intent(Search_List_Activity.this,Search_List_Activity.class);
intent.putExtra("keyword",keyword);
category_get_id=category_id.get(position);
System.out.println("CATEGORY NAME-->"+category_get_id);
startActivity(intent);
}
});
return dialog_category;
}
return null;
}
}
This gives the following exception.
06-07 16:39:12.660: ERROR/AndroidRuntime(986): FATAL EXCEPTION: main
06-07 16:39:12.660: ERROR/AndroidRuntime(986): java.lang.IllegalArgumentException: View not attached to window manager
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.app.Dialog.dismissDialog(Dialog.java:278)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.app.Dialog.access$000(Dialog.java:71)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.app.Dialog$1.run(Dialog.java:111)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.app.Dialog.dismiss(Dialog.java:268)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at org.bizrate.tablet.Search_List_Activity$1.handleMessage(Search_List_Activity.java:174)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.os.Handler.dispatchMessage(Handler.java:99)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.os.Looper.loop(Looper.java:123)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at java.lang.reflect.Method.invokeNative(Native Method)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at java.lang.reflect.Method.invoke(Method.java:521)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-07 16:39:12.660: ERROR/AndroidRuntime(986): at dalvik.system.NativeStart.main(Native Method)
Hey. All I want to add. One more thing here when I remove the progress bar code from this .it code works fine. But I have to implement with a progress bar. please, help. Thank you all.