Thursday, November 8, 2012


package androidexperts.app.realestate;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import androidexperts.app.realestate.mapdata.ShowAreas;
import androidexperts.app.realestate.mapdata.ShowSelectedCityNew;

public class SearchProperty extends Activity
{
AllMethods mAllMethods;
public TextView txt_company_name;
Cursor mCursor_company_detail;
Cursor mCursor_PriceRange;
public String[] priceRange;
String range="";
Typeface mTypeface;
public Button btn_selection_criteria;
public Button btn_selection_by_code;
public Button btn_sale;
public Button btn_rent;
public Button btn_amount;
public Button btn_range;
public Button btn_search;
public Button btn_back;
public Button btn_user_account;
public Button btn_search_yellow;
public String sp_custmor_id = "sp_custmor_id";
public String customer_id = "";
public ArrayAdapter<String> mArray_countryAdapter;
public ArrayAdapter<String> mArray_stateAdapter;

public ArrayList<Integer> id_countryArrayList;
public ArrayList<Integer> id_stateArrayList;


private int mSelected = -1;


public RelativeLayout RelativeLayout_text;
public RelativeLayout RelativeLayout_scroll;

public RelativeLayout Relative_rel_bottom_user;
public RelativeLayout Relative_bottombar;

public SharedPreferences SharedPreferences_login;

public TextView txt_property_type;
public TextView txt_property_sub_type;
public TextView txt_codetext;
public TextView txt_select_city;
public TextView txt_select_area;
// public TextView txt_raw;

public DatabaseConnectionAPI mDatabaseConnectionAPI;

public EditText edt_text_code;

public Spinner spinner_state;
public Spinner spinner_min_budget;
public Spinner spinner_max_budget;
public Spinner spinner_max_sqFt;
public Spinner spinner_min_sqFt;
public Spinner spinner_range;
public Spinner spinrCountry;
public Spinner spinrState;

Integer minSqFeet=0;
Integer maxSqFeet=0;

public StaticValues mStaticValues;

public Cursor mCursor_property_type;
public Cursor mCursor_country;
public Cursor mCursor_states;
public Cursor mCursor_property_sub_type;
public Cursor mCursor_select_city;
public Cursor mCursor_select_area;
public Cursor mCursor;
public Cursor mCursor_searchcode;
public Cursor mCursor_setSpinnerData;
public Cursor mCursor_setTextData;

public String[] getpropertysubId = {};
public String[] getpropertysubId1 = {};
public String[] getselectedcity = {};

public String[] getselectedarea = {};
public String[] getListSelectedCityIds={};
public String[] getListSelectedAreaIds={};
public String[] getListSelectedTypeIds={};
public String[] getListSelectedSubTypeIds={};
// public String[] country_array = {};
public String[] state_array = {};

public String selected_country = "";
public String selected_state = "";
public String getState = "";
public String selected_type = "";
public String selected_city="";
public String selected_subtype = "";
public String selected_area = "";
public String country = "";
// public String gettype_name = "";
// public String getsubtype_name = "";
// public String getsaletext = "";
// public String getrenttext = "";
// public String getcountry_name = "";
// public String getstate_name = "";
// public String getcity_name = "";
// public String getarea_name = "";
// public String getprice = "";
// public String getsquarefeet = "";
public String getproperty_code = "";
public String purpose = "S";
public String sp_file_name = "authentication" ;
public String logged_in = "loggedin";


//FinalData Variable
public String selectedCountryID="";
public String selectedStateID="";
public String selectedCityIDs="";
public String selectedAreaIds="";
public String selectedPropertyTypeIDs="";
public String selectedPropertySubTypeIDs="";
String minBudget="";
String maxBudget="";
String minSqFt="";
String maxSqFt="";

Activity mActivity;
public Integer[] state_ids;

public int getStateId=0;

int minBudgetId;
int maxBudgetId;

String[] pricep = { "Min Price","0", "1000000", "2000000", "3000000", "4000000",
"5000000", "6000000", "7000000", "8000000", "9000000", "10000000",
};

String[]  priceMax = {"Max Price"};
String[]  squareMax = {"Max Sqft"};

String[] squareFeet = {"Min Sqft", "50", "100", "150", "200", "250", "300", "350",
"400","450", "500","550","600","650","700","750","800","850","900",
"950","1000","1050","1100","1150","1200","1250","1300","1350","1400",
"1450","1500","1550","1600","1650","1700","1750","1800","1850","1900","1950","2000",
"2050","2100","2150","2200","2250","2300","2350","2400","2450","2500","2550","2600",
"2650","2700","2750","2800","2850","2900","2950","3000"};

public String[]  array_list_propertycode= {};


public boolean[] boolean_subtype_checked;
public boolean[] boolean_city_checked;
public boolean[] boolean_area_checked;
private boolean[] boolean_type_checked;

public boolean boolean_mFlag = false;
public boolean boolean_amount = true;
public boolean boolean_log_in;


public ArrayList<Integer> idStateArrayList;
public ArrayList<Integer> idCountryArrayList;
public ArrayList<Integer> stateIdArrayList;

public ArrayAdapter<String> spiner_country_arrayAdapter;
public ArrayAdapter<String> spiner_state_arrayAdapter;

public ArrayAdapter<String> mArrayMinPriceAdapter;
public ArrayAdapter<String> mArrayMaxPriceAdapter;

public ArrayAdapter<String> mArrayMinSqFeetAdapter;
public ArrayAdapter<String> mArrayMaxSqFeetAdapter;

public ArrayAdapter<String> mArray_priceRangeAdapter;


public ArrayAdapter<CharSequence> price_range_arrayadapter;

int [] array_int_property_id;
String [] array_string_purpose;
double [] array_double_latitute;
double [] array_double_longitude;

public Intent mIntent;
RelativeLayout RelativeLayout_root;

@Override
public void onCreate(Bundle savedInstanceState)

{
super.onCreate(savedInstanceState);
setContentView(R.layout.latest_search);

RelativeLayout_scroll = (RelativeLayout) findViewById(R.id.rel_scl);
RelativeLayout_root = (RelativeLayout) findViewById(R.id.root);
Relative_rel_bottom_user=(RelativeLayout)findViewById(R.id.rel_bottom_user);
Relative_bottombar=(RelativeLayout)findViewById(R.id.rel_bottombar);
mActivity=this;
mIntent = new Intent();
mAllMethods=new AllMethods(mActivity);
mDatabaseConnectionAPI = new DatabaseConnectionAPI(mActivity);

mStaticValues=new StaticValues();
txt_codetext = (TextView) findViewById(R.id.tv_codetext);
txt_select_area = (TextView) findViewById(R.id.tv_select_area);
txt_select_city = (TextView) findViewById(R.id.tv_select_city);
edt_text_code = (EditText) findViewById(R.id.edt_text_code);


btn_amount = (Button) findViewById(R.id.btn_amount);
btn_range = (Button) findViewById(R.id.btn_range);
btn_rent = (Button) findViewById(R.id.btn_rent);
btn_sale = (Button) findViewById(R.id.btn_sale);
btn_search = (Button) findViewById(R.id.btn_search_property);
btn_selection_by_code = (Button) findViewById(R.id.btn_selection_by_code);
btn_selection_criteria = (Button) findViewById(R.id.btn_selection_criteria);
btn_selection_by_code.setBackgroundResource(R.drawable.text_box);
txt_property_sub_type = (TextView) findViewById(R.id.tv_property_sub_type);
txt_property_type = (TextView) findViewById(R.id.tv_property_type);
btn_back = (Button) findViewById(R.id.btn_back);
RelativeLayout_text = (RelativeLayout) findViewById(R.id.rel_text);
spinrCountry = (Spinner) findViewById(R.id.spinr_country);
spinrState = (Spinner) findViewById(R.id.spinr_state);
btn_user_account=(Button)findViewById(R.id.btn_useraccount);
btn_search_yellow=(Button)findViewById(R.id.btn_search);
txt_company_name=(TextView)findViewById(R.id.about_us_txt_name);

spinner_max_budget = (Spinner) findViewById(R.id.spinner_max);
spinner_min_budget = (Spinner) findViewById(R.id.spinner_min);
spinner_min_sqFt = (Spinner) findViewById(R.id.spinner_min_sqr);
spinner_max_sqFt = (Spinner) findViewById(R.id.spinner_max_sqr);
spinner_range = (Spinner) findViewById(R.id.spinner_range);
mTypeface=Typeface.createFromAsset(getAssets(),"fonts/Rupee.ttf");

mAllMethods.setCompanyTextAndLogo(txt_company_name);
view_visibility();

txt_company_name.setText(RealEstateApplication.companyNameTitle);

btn_search_yellow.setOnClickListener(new OnClickListener()
{

@Override
public void onClick(View v)
{
mIntent=new Intent(SearchProperty.this, ShowSelectedCityNew.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mIntent.putExtra(mStaticValues.Button,mStaticValues.NOButtonValue);
startActivity(mIntent);
}
});
btn_user_account.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
mIntent.setClass(SearchProperty.this, UserDialog.class);
// mIntent.putExtra(mStaticValues.current_purpose, mStaticValues.All);
RealEstateApplication.CURRENT_PURPOSE = mStaticValues.All;
startActivity(mIntent);
}
});


setSpinnerItem();
//
mCursor_PriceRange = mDatabaseConnectionAPI
.onSelectLocId("SELECT * FROM  Price_Range_Master ");
// startManagingCursor(mCursor_PriceRange);
// LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
// View convertView = inflater
// .inflate(R.layout.text_data_spinner, null);
//// txt_raw=(TextView)convertView.findViewById(R.id.spinnerTarget);
////
priceRange = new String[mCursor_PriceRange.getCount()];
//////
for (int i = 0; i < mCursor_PriceRange.getCount(); i++) {
mCursor_PriceRange.moveToPosition(i);
String no1 = mCursor_PriceRange.getString(mCursor_PriceRange
.getColumnIndex(mStaticValues.range_start));
// //System.out.println("No1..." + no1);
String no2 = mCursor_PriceRange.getString(mCursor_PriceRange.getColumnIndex(mStaticValues.range_end));
priceRange[i] =" ` " +  no1 + " - " +" ` " + no2;
}

spinner_range.setAdapter(new MyCustomSpinnerAdapter(SearchProperty.this, R.layout.customspinneritem, priceRange));

mCursor = mDatabaseConnectionAPI.onQueryGetCursor(mStaticValues.country_master, null, null, null,
null, null, null);
mArray_countryAdapter = new ArrayAdapter<String>(
getApplicationContext(), R.layout.text_data_simple_spinner);

id_countryArrayList = new ArrayList<Integer>();
for (int i = 0; i < mCursor.getCount(); i++) {
mCursor.moveToPosition(i);
mArray_countryAdapter.add(mCursor.getString(1));
id_countryArrayList.add(mCursor.getInt(0));
mArray_countryAdapter.notifyDataSetChanged();
}

mArray_countryAdapter.setDropDownViewResource(R.layout.text_data_spinner);
spinrCountry.setAdapter(mArray_countryAdapter);


spinrCountry.setOnItemSelectedListener(new OnItemSelectedListener()
{

@Override
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
int CountryID = id_countryArrayList.get(position);
selectedCountryID  =String.valueOf(CountryID);
country = (String) (spinrCountry.getSelectedItem());
selected_state="";
selectedStateID="";

mCursor_setSpinnerData=mDatabaseConnectionAPI.setSpinnerData(mStaticValues.state_master, CountryID);

mArray_stateAdapter = new ArrayAdapter<String>(
getApplicationContext(),
R.layout.text_data_simple_spinner);

id_stateArrayList = new ArrayList<Integer>();
for (int i = 0; i < mCursor_setSpinnerData.getCount(); i++) {
mCursor_setSpinnerData.moveToPosition(i);
id_stateArrayList.add(mCursor_setSpinnerData.getInt(0));
mArray_stateAdapter.add(mCursor_setSpinnerData.getString(1));
mArray_stateAdapter.notifyDataSetChanged();
}

mArray_stateAdapter
.setDropDownViewResource(R.layout.text_data_spinner);
spinrState.setAdapter(mArray_stateAdapter);

// mCustomBaseAdapter = new CustomBaseAdapter(SearchProperty.this,
// getLayoutInflater(), R.layout.custombase, Color.BLACK);
// stateIdArrayList = new ArrayList<Integer>();
// for (int i = 0; i < mCursor.getCount(); i++)
// {
// mCursor.moveToPosition(i);
// stateIdArrayList.add(mCursor.getInt(0));
// mCustomBaseAdapter.array_list_dataset.add(mCursor.getString(1));
// mCustomBaseAdapter.notifyDataSetChanged();
// }
if (spinrState.getCount() == 0)
{
getState = "";
getselectedcity = new String[0];
getListSelectedCityIds = new String[0];
removeALLSelected();
}
}

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

}
});

spinrState.setOnItemSelectedListener(new OnItemSelectedListener()
{

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
long arg3)
{

int getstateId = id_stateArrayList.get(pos);

////System.out.println("getstateID"+getstateId);

getState = (String) (spinrState.getSelectedItem());

selectedStateID = String.valueOf(getstateId);
mCursor_setSpinnerData=mDatabaseConnectionAPI.setSpinnerData(mStaticValues.city_master, getstateId);
// mCursor_select_city = mDatabaseConnectionAPI

// .ExecuteQueryGetCursor(" SELECT * from " + mStaticValues.city_master +" where "+ mStaticValues.state_id + " = "
// + getstateId + " And is_active like 'y'");

getselectedcity = new String[mCursor_setSpinnerData.getCount()];
getListSelectedCityIds = new String[mCursor_setSpinnerData.getCount()];
boolean_city_checked = new boolean[mCursor_setSpinnerData.getCount()];
for (int i = 0; i < mCursor_setSpinnerData.getCount(); i++)
{

mCursor_setSpinnerData.moveToPosition(i);
getselectedcity[i] = mCursor_setSpinnerData.getString(mCursor_setSpinnerData.getColumnIndex(mStaticValues.city_name));
getListSelectedCityIds[i] = mCursor_setSpinnerData.getString(mCursor_setSpinnerData.getColumnIndex(mStaticValues.city_id));
boolean_city_checked[i] = false;

}
mCursor_setSpinnerData.close();
removeALLSelected();
}

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

}
});


mCursor_property_type = mDatabaseConnectionAPI.getPropertyType();
// .ExecuteQueryGetCursor(" SELECT "+ mStaticValues.type_name + " FROM " + mStaticValues.property_type_master + " WHERE " + mStaticValues.parent_id + " = 0");
getpropertysubId = new String[mCursor_property_type.getCount()];
getListSelectedTypeIds = new String[mCursor_property_type.getCount()];

boolean_type_checked = new boolean[mCursor_property_type.getCount()];
for (int i = 0; i < mCursor_property_type.getCount(); i++) {

mCursor_property_type.moveToPosition(i);
getpropertysubId[i] = mCursor_property_type
.getString(mCursor_property_type
.getColumnIndex(mStaticValues.type_name));
getListSelectedTypeIds[i]=mCursor_property_type.getString(mCursor_property_type.getColumnIndex(mStaticValues.type_id));
boolean_type_checked[i] = false;
}


btn_amount.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
spinner_max_budget.setVisibility(View.VISIBLE);
spinner_min_budget.setVisibility(View.VISIBLE);
spinner_range.setVisibility(View.GONE);
btn_range.setBackgroundResource(R.drawable.range_unselected);
btn_amount.setBackgroundResource(R.drawable.amount_selected);
boolean_amount = true;

}
});

btn_range.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
spinner_max_budget.setVisibility(View.GONE);
spinner_min_budget.setVisibility(View.GONE);
spinner_range.setVisibility(View.VISIBLE);
btn_range.setBackgroundResource(R.drawable.range_selected);
btn_amount.setBackgroundResource(R.drawable.amount_unselected);
boolean_amount = false;
}
});

btn_rent.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
btn_rent.setBackgroundResource(R.drawable.new_rent_selected);
btn_sale.setBackgroundResource(R.drawable.sell_unselected);
purpose = "R";
}
});

btn_sale.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
btn_rent.setBackgroundResource(R.drawable.new_rent_unselected);
btn_sale.setBackgroundResource(R.drawable.sell_selected);
purpose = "S";
}
});
btn_back.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
mIntent=new Intent(SearchProperty.this, ShowSelectedCityNew.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mIntent.putExtra(mStaticValues.Button,mStaticValues.NOButtonValue);
startActivity(mIntent);
}
});

btn_selection_by_code.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
txt_select_city.setText("");
txt_select_area.setText("");
txt_property_type.setText("");
txt_property_sub_type.setText("");
removeALLSelected();
edt_text_code.setText(R.string.sample_code);
btn_selection_by_code.setBackgroundResource(R.drawable.btn_orange);
btn_selection_criteria.setBackgroundResource(R.drawable.text_box);
btn_selection_by_code.setTextColor(Color.WHITE);
btn_selection_criteria.setTextColor(Color.GRAY);
RelativeLayout_scroll.setVisibility(View.GONE);
RelativeLayout_text.setVisibility(View.VISIBLE);
boolean_mFlag = true;
}
});


btn_selection_criteria.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
edt_text_code.setText("");
btn_selection_by_code.setBackgroundResource(R.drawable.text_box);
btn_selection_criteria.setBackgroundResource(R.drawable.btn_orange);
btn_selection_by_code.setTextColor(Color.GRAY);
btn_selection_criteria.setTextColor(Color.WHITE);
RelativeLayout_scroll.setVisibility(View.VISIBLE);
RelativeLayout_text.setVisibility(View.GONE);
boolean_mFlag = false;
}
});
txt_select_city.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
propertyCityDialog();

}
});
txt_select_area.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
propertyAreaDialog();
}
});

txt_property_type.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
proprtyTypedialog();

}
});

txt_property_sub_type.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
propertySubTypeDialog();
}


});


btn_search.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{

SharedPreferences_login = getSharedPreferences(sp_file_name,Context.MODE_PRIVATE);
boolean_log_in = SharedPreferences_login.getBoolean(logged_in, false);

// if(selected_subtype.equalsIgnoreCase(mStaticValues.Blank) && selected_area.equalsIgnoreCase(mStaticValues.Blank) && selected_city.equalsIgnoreCase(mStaticValues.Blank) && !selected_type.equalsIgnoreCase(mStaticValues.Blank))
// {
// mAllMethods.alertDialogForValidation(mActivity,
// mStaticValues.MessageErrorTitle,
// mStaticValues.EnterField,false);
// txt_select_city.requestFocus();
// }

if(boolean_mFlag)
{
if(edt_text_code.getText().toString().trim().length()==0)
{

mAllMethods.alertDialogForValidation(mActivity,
mStaticValues.MessageErrorTitle,
mStaticValues.EnterPropertycode,false);
////System.out.println("Flag VAKLUE "+boolean_mFlag);

}
else
{
getproperty_code = edt_text_code.getText().toString();

String[] mStringsSplitted= getproperty_code.split(",");
String sqlQuery= "SELECT * from " + mStaticValues.property_master + " where is_active like 'y' AND " + mStaticValues.property_code + "=" ;

for (int i = 0; i < mStringsSplitted.length; i++)
{

if((i+1)==mStringsSplitted.length)
sqlQuery+= "'"+mStringsSplitted[i]+"'";
else
sqlQuery+= "'"+mStringsSplitted[i]+"' or "+ mStaticValues.property_code + "=";
}
mCursor_searchcode =mDatabaseConnectionAPI.ExecuteQueryGetCursor(sqlQuery);
mAllMethods.setAllPropertyData(mCursor_searchcode,false);
getproperty(mCursor_searchcode);
////System.out.println("Final Query: "+sqlQuery);


}
}
else
{
String search_query="";
if(selectedStateID.trim().length()>0)
{
search_query = "SELECT pm.property_id, pm.property_code, pm.property_name," +
"pm.city_id, pm.area_id, pm.type_id, pm.price, pm.purpose, pm.property_area, " +
"pm.property_description, pm.latitude, pm.longitude, pm.video_url, pm.is_active ,"

+" CASE"
+" WHEN ptm.parent_id > 0 THEN"
+" ( SELECT tmp_ptm.type_name"
+" FROM Property_Type_Master AS tmp_ptm"
+" WHERE tmp_ptm.type_id = ptm.parent_id )"
+" END AS 'parent_name',"

+" CASE "
+" WHEN ptm.parent_id > 0 THEN"
+" ptm.parent_id "
+" WHEN ptm.parent_id = 0 THEN"
+" ptm.type_id"
+" END AS 'type_id', ptm.type_name"

+" FROM Property_Master AS pm "
+" LEFT JOIN City_Master AS citym ON citym.city_id = pm.city_id"
+" INNER JOIN Country_Master AS cm ON cm.country_id = sm.country_id"
+" INNER JOIN State_Master AS sm ON citym.state_id = sm.state_id  "
+" LEFT JOIN Property_Type_Master AS ptm ON ptm.type_id = pm.type_id"
+" LEFT JOIN Area_Master AS aream ON aream.area_id = pm.area_id "
+" WHERE pm.is_active like 'Y' AND cm.country_id="+ selectedCountryID
+" AND sm.state_id =  "+selectedStateID+" AND pm.purpose='"+purpose+"'";


if(selectedCityIDs.trim().length()>0)
{
search_query= search_query+" AND pm.city_id IN ( "+selectedCityIDs+" )";
}
if(selectedAreaIds.trim().length()>0)
{
search_query= search_query+" AND  pm.area_id IN ( "+selectedAreaIds+" )";
}

if(selectedPropertyTypeIDs.trim().length()>0)
{
if(selectedPropertySubTypeIDs.trim().length()>0)
{ search_query= search_query+
" AND pm.type_id IN ( "+ selectedPropertySubTypeIDs+" ) ";
}
else
{
search_query= search_query+
" AND pm.type_id IN ( "+
" Select "+
" tmp1_ptm.type_id "+
" FROM Property_Type_Master AS tmp1_ptm "+
" WHERE tmp1_ptm.type_id IN ( "+
" SELECT tmp2.type_id FROM Property_Type_Master AS tmp2 "+
" WHERE  "+
" CASE  "+
" WHEN tmp2.parent_id = 0 THEN "+
" tmp2.type_id IN ( " +selectedPropertyTypeIDs +" ) "+
" WHEN tmp2.parent_id > 0 THEN "+
" tmp2.parent_id IN ( " +selectedPropertyTypeIDs +" ) "+
" END "+
" ) "+
" ) ";
}
}
String[] priceData = returnRealPrice(new String[]{minBudget,maxBudget});
if(priceData[0].trim().length()>0 && priceData[1].trim().length()>0)
{
search_query = search_query+" AND pm.price BETWEEN "+ priceData[0]+" AND "+priceData[1];
}
if(minSqFt.trim().length()>0 && maxSqFt.trim().length()>0)
{
search_query = search_query+" AND pm.property_area BETWEEN "+ minSqFt+" AND "+maxSqFt;
}


mCursor_searchcode =mDatabaseConnectionAPI.ExecuteQueryGetCursor(search_query);
mAllMethods.setAllPropertyData(mCursor_searchcode,false);
getproperty(mCursor_searchcode);
}
else
{
mAllMethods.alertDialogForValidation(mActivity,
mStaticValues.MessageErrorTitle,
mStaticValues.StateNotAvail,false);
}

}
}
});
}

public String[] returnRealPrice(String[] min_maxPrice)
{
String min_price = "";
String max_price = "";
String[] data = new String[]{min_price,max_price};

try {
if (boolean_amount)
{
min_price = min_maxPrice[0];
min_price = URLEncoder.encode(min_price, "utf-8");
min_price = URLDecoder.decode(min_price.replaceAll("%24", ""));
max_price = min_maxPrice[1];
max_price = URLEncoder.encode(max_price, "utf-8");
max_price = URLDecoder.decode(max_price.replaceAll("%24", ""));
}
else
{

String range = spinner_range.getSelectedItem()
.toString();
String[] range_div = range.split("-");
min_price = range_div[0];
max_price = range_div[1];

min_price = URLEncoder.encode(min_price, "utf-8");
min_price = URLDecoder.decode(min_price.replaceAll("%24", ""));
min_price = min_price.replaceAll("`", "");
max_price = URLEncoder.encode(max_price, "utf-8");
max_price = URLDecoder.decode(max_price.replaceAll("%24", ""));
max_price = max_price.replaceAll("`", "");

}
data[0] = min_price;
data[1] = max_price;
} catch (Exception e) {
e.printStackTrace();
}
return data;

}

// CUSTOM SPINNER ADAPTER
public class MyCustomSpinnerAdapter extends ArrayAdapter<String>
{

String[] newPriceRange;
Activity mActivity;
ArrayAdapter<String>temp_array_adapter_pricerange;

public MyCustomSpinnerAdapter(Activity mActivity, int textViewResourceId, String[] newPriceRange) {
super(mActivity, textViewResourceId, newPriceRange);
}

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getCustomView(position, convertView, parent);
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
return getCustomView(position, convertView, parent);
}

public View getCustomView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater=getLayoutInflater();
convertView=inflater.inflate(R.layout.customspinneritem, parent, false);
mTypeface=Typeface.createFromAsset(getAssets(),"fonts/Rupee.ttf");
TextView txt_raw=(TextView)convertView.findViewById(R.id.spinnerTargetRaw);
txt_raw.setText(priceRange[position]);
txt_raw.setTypeface(mTypeface,Typeface.BOLD);
return convertView;
}

}

public void setSpinnerItem()
{

mArrayMinPriceAdapter = new ArrayAdapter<String>(
getApplicationContext(), R.layout.text_data_simple_spinner, pricep);

mArrayMinPriceAdapter.setDropDownViewResource(R.layout.text_data_spinner);
spinner_min_budget.setAdapter(mArrayMinPriceAdapter);

spinner_min_budget.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View v, int pos,
long id)
{

minBudgetId = (int) (spinner_min_budget.getSelectedItemId());

minBudget = (String) spinner_min_budget.getSelectedItem();
if(pos==0)
{
mArrayMaxPriceAdapter = new ArrayAdapter<String>(
getApplicationContext(),
R.layout.text_data_simple_spinner, priceMax);
mArrayMaxPriceAdapter
.setDropDownViewResource(R.layout.text_data_spinner);
spinner_max_budget.setAdapter(mArrayMaxPriceAdapter);
minBudget="";


}
else
{
minBudget = (String) spinner_min_budget.getSelectedItem();
try {
String one = (String) spinner_min_budget
.getItemAtPosition(minBudgetId);
System.out.println("ONE ="+one);
String[] max = new String[spinner_min_budget.getCount()
                         - minBudgetId];
String j = one;

System.out.println("minBudgetId= "+minBudgetId);
System.out.println("minBudget= "+minBudget);
System.out.println("J= "+j);
System.out.println("spinner_min_budget.getCount() ="+spinner_min_budget.getCount());
if (minBudgetId < (spinner_min_budget.getCount() - 1)) {
Log.d("if", "enter");

String two = (String) spinner_min_budget
.getItemAtPosition(minBudgetId + 1);
int increment = Integer.parseInt(two)
- Integer.parseInt(one);
System.out.println("Two= "+two);
System.out.println("INC ="+increment);
for (int i = 0; i < spinner_min_budget.getCount()
- minBudgetId; i++) {
max[i] = String.valueOf(j);
j = String.valueOf(Integer.parseInt(j) + increment);
System.out.println("max ="+max[i]);

}
} else {
Log.d("else", "enter");
for (int i = 0; i < spinner_min_budget.getCount()
- minBudgetId; i++)
{
max[i] = one;
}
}

mArrayMaxPriceAdapter = new ArrayAdapter<String>(
getApplicationContext(),
R.layout.text_data_simple_spinner, max);
mArrayMaxPriceAdapter
.setDropDownViewResource(R.layout.text_data_spinner);
spinner_max_budget.setAdapter(mArrayMaxPriceAdapter);
}
catch (Exception e)
{
// e.printStackTrace();
}
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0)
{

}
});


mArrayMinSqFeetAdapter = new ArrayAdapter<String>(getApplicationContext(),
R.layout.text_data_simple_spinner, squareFeet);

mArrayMinSqFeetAdapter.setDropDownViewResource(R.layout.text_data_spinner);
spinner_min_sqFt.setAdapter(mArrayMinSqFeetAdapter);

spinner_min_sqFt.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {

minSqFeet = (int) (spinner_min_sqFt.getSelectedItemId());

minSqFt = (String) spinner_min_sqFt.getSelectedItem();
if(pos==0)
{
mArrayMaxSqFeetAdapter = new ArrayAdapter<String>(
getApplicationContext(),
R.layout.text_data_simple_spinner, squareMax);
mArrayMaxSqFeetAdapter
.setDropDownViewResource(R.layout.text_data_spinner);
spinner_max_sqFt.setAdapter(mArrayMaxSqFeetAdapter);
minSqFt="";
}

else
{
minSqFt = (String) spinner_min_sqFt.getSelectedItem();


try {
String one = (String) spinner_min_sqFt
.getItemAtPosition(minSqFeet);

String[] max = new String[spinner_min_sqFt.getCount()
                         - minSqFeet];

String j = one;
System.out.println("Spinner Counter:"+spinner_min_sqFt.getCount());
System.out.println("MinSqFeet"+minSqFeet);
if (minSqFeet < (spinner_min_sqFt.getCount()-1 ))
{
Log.d("if", "enter");
String two = (String) spinner_min_sqFt
.getItemAtPosition(minSqFeet + 1);
int increment = Integer.parseInt(two)
- Integer.parseInt(one);

for (int i = 0; i < spinner_min_sqFt.getCount() - minSqFeet; i++) {
max[i] = String.valueOf(j);
j = String.valueOf(Integer.parseInt(j) + increment);
}
}
else
{
Log.d("else", "enter");
for (int i = 0; i < spinner_min_sqFt.getCount() - minSqFeet; i++) {
max[i] = one;
}
}

mArrayMaxSqFeetAdapter = new ArrayAdapter<String>(
getApplicationContext(),
R.layout.text_data_simple_spinner, max);
mArrayMaxSqFeetAdapter
.setDropDownViewResource(R.layout.text_data_spinner);
spinner_max_sqFt.setAdapter(mArrayMaxSqFeetAdapter);

}

catch (Exception e)
{
// e.printStackTrace();
}
}
}

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

}
});


spinner_max_budget.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3)
{
maxBudgetId = (int) (spinner_max_budget.getSelectedItemId());

if(minBudget.trim().length()==0 && pos==0)
{
maxBudget="";
}
else
{
maxBudget = (String) spinner_max_budget.getSelectedItem();
}
System.out.println("maxBudget@@@  "+maxBudget);

}

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

}
});


spinner_max_sqFt.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int pos, long arg3)
{
maxSqFeet = (int) (spinner_max_sqFt.getSelectedItemId());

if(minSqFt.trim().length()==0 && pos==0)
{
maxSqFt="";
}
else
{
maxSqFt = (String) spinner_max_sqFt.getSelectedItem();
}
System.out.println("MAxSQu FEET"+maxSqFt);
}

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

}

public void propertyCityDialog() {
try
{
selected_city="";
selectedCityIDs="";
// Log.d("GetCount Type :",
// String.valueOf(mCursor_setSpinnerData.getCount()));
final Builder build = new Builder(SearchProperty.this);
build.setTitle(mStaticValues.CitySelection);
build.setCancelable(true);
OnMultiChoiceClickListener onClick = new OnMultiChoiceClickListener()
{
@Override
public void onClick(final DialogInterface dialog,
final int which, final boolean isChecked)
{

if (isChecked)
{
if (boolean_city_checked[which])
{
final int oldVal = mSelected;
final AlertDialog alert = (AlertDialog) dialog;
final ListView list = alert.getListView();
list.setItemChecked(oldVal, false);
}
mSelected = which;
boolean_city_checked[which] = true;
}
else
{
boolean_city_checked[which] = false;
txt_select_city.setText("");

}
}
};

if(getselectedcity.length>0)
{
build.setMultiChoiceItems(getselectedcity, boolean_city_checked,
onClick);
build.setPositiveButton("Done",
new DialogInterface.OnClickListener()
{
public void onClick(final DialogInterface dialog,
final int which)
{

txt_select_area.setText("");
txt_property_sub_type.setText("");
txt_property_type.setText("");

if (boolean_city_checked.length == -1)
Log.d("Selection",
"You didn't select anything.");
else
for (int j = 0; j < getselectedcity.length; j++)
{
if (boolean_city_checked[j])
{
Log.d("Checked", getselectedcity[j].toString());
selected_city = selected_city
+ "\'"
+ getselectedcity[j]
                 .toString() + "\', ";

if(selectedCityIDs.trim().length()>0)
{
selectedCityIDs = selectedCityIDs
+ ","
+ getListSelectedCityIds[j].toString();
}
else
selectedCityIDs = getListSelectedCityIds[j].toString();
}
else
{
Log.d("not Checked",
getselectedcity[j]
               .toString());
}
}
if (selected_city.length() > 0)
{
selected_city = (String) selected_city
.subSequence(0,
selected_city.length() - 2);
txt_select_city.setText(selected_city
.replaceAll("\'", ""));

// selectedCityIDs= (String)selectedCityIDs.subSequence(0,selected_city.length() - 1);

System.out.println("selectedCityIDs "+selectedCityIDs);
mCursor_setTextData=mDatabaseConnectionAPI.setTextData(mStaticValues.area_master, selectedCityIDs);
// mCursor_select_area=mDatabaseConnectionAPI.setTextData(mStaticValues.area_master, selected_city);
// mCursor_select_area = mDatabaseConnectionAPI
// .ExecuteQueryGetCursor("Select area_name FROM  Area_Master"
// + " WHERE city_id in"
// + "(SELECT city_id FROM City_Master WHERE city_name in "
// + " ("
// + selected_city
// + ")) GROUP BY area_name");
// startManagingCursor(mCursor_setTextData);
mCursor_setTextData.moveToFirst();
getselectedarea = new String[mCursor_setTextData
                            .getCount()];
getListSelectedAreaIds = new String[mCursor_setTextData
                                   .getCount()];

boolean_area_checked = new boolean[mCursor_setTextData
                                  .getCount()];
for (int i = 0; i < mCursor_setTextData.getCount(); i++) {

mCursor_setTextData.moveToPosition(i);
getselectedarea[i] = mCursor_setTextData.getString(mCursor_setTextData
.getColumnIndex(mStaticValues.area_name));
getListSelectedAreaIds[i] = mCursor_setTextData.getString(mCursor_setTextData
.getColumnIndex(mStaticValues.area_id));
boolean_area_checked[i] = false;
txt_select_area.setText("");
}
}

}
});
build.show();
}

else
{

mAllMethods.alertDialogForValidation(mActivity,
mStaticValues.MessageErrorTitle,
mStaticValues.NoCityFound,false);
}
}
catch (Exception e)
{
// e.printStackTrace();
}
}

public void propertyAreaDialog()
{
try {
selected_area="";
Log.d("GetCount Type :",
String.valueOf(mCursor_setTextData.getCount()));
final Builder build = new Builder(SearchProperty.this);
build.setTitle(mStaticValues.AreaSelection);
build.setCancelable(true);
OnMultiChoiceClickListener onClick = new OnMultiChoiceClickListener()
{
@Override
public void onClick(final DialogInterface dialog,
final int which, final boolean isChecked)
{

if (isChecked)
{
if (boolean_area_checked[which])
{
final int oldVal = mSelected;
final AlertDialog alert = (AlertDialog) dialog;
final ListView list = alert.getListView();
list.setItemChecked(oldVal, false);
}
mSelected = which;
boolean_area_checked[which] = true;
}
else
{
boolean_area_checked[which] = false;
txt_select_area.setText("");
}
}
};

build.setMultiChoiceItems(getselectedarea, boolean_area_checked,
onClick);
build.setPositiveButton("Done",
new DialogInterface.OnClickListener()
{
public void onClick(final DialogInterface dialog,
final int which)
{
if (boolean_area_checked.length == -1)
{
Log.d("Selection",
"You didn't select anything.");
txt_select_area.setText("");
}
else
{
for (int j = 0; j < getselectedarea.length; j++)
{
if (boolean_area_checked[j])
{
Log.d("Checked", getselectedarea[j]
                                .toString());
selected_area = selected_area
+ "\'"
+ getselectedarea[j]
                 .toString() + "\', ";


if(selectedAreaIds.trim().length()>0)
{
selectedAreaIds = selectedAreaIds
+ ","
+ getListSelectedAreaIds[j].toString();
}
else
selectedAreaIds = getListSelectedAreaIds[j].toString();
System.out.println("selectedAreaIds "+selectedAreaIds);
}
else
Log.d("not Checked",
getselectedarea[j]
               .toString());
}
}
if (selected_area.length() > 0)
{
selected_area = (String) selected_area
.subSequence(0,
selected_area.length() - 2);
txt_select_area.setText(selected_area
.replaceAll("\'", ""));
}

else {
selected_area = "";
txt_select_area.setText(selected_area);
}
}
});
build.show();

} catch (Exception e) {
// e.printStackTrace();
}
}

/**
* This Method is For View Bottombar Visibility as per SharedPreferce value Set.
*/
public void view_visibility()
{
SharedPreferences_login = getSharedPreferences(sp_file_name,Context.MODE_PRIVATE);
boolean_log_in = SharedPreferences_login.getBoolean(logged_in, false);
if (boolean_log_in)
{
Relative_rel_bottom_user.setVisibility(View.VISIBLE);
Relative_bottombar.setVisibility(View.INVISIBLE);
customer_id = SharedPreferences_login.getString(sp_custmor_id, "0");
} else
{
Relative_bottombar.setVisibility(View.VISIBLE);
Relative_rel_bottom_user.setVisibility(View.INVISIBLE);
}
}


public void removeALLSelected()
{
txt_select_city.setText("");
txt_property_type.setText("");
txt_property_sub_type.setText("");
txt_select_area.setText("");
getpropertysubId1 = new String[0];
getListSelectedSubTypeIds= new String[0];
getselectedarea = new String[0];
getListSelectedAreaIds = new String[0];
if(boolean_city_checked!=null)
{
for (int i = 0; i < boolean_city_checked.length; i++)
{
boolean_city_checked[i]=false;
}
}

if(boolean_area_checked!=null)
{
for (int i = 0; i < boolean_area_checked.length; i++)
{
boolean_area_checked[i]=false;
}
}

if(boolean_type_checked!=null)
{
for (int i = 0; i < boolean_type_checked.length; i++)
{
boolean_type_checked[i]=false;
}
}
if(boolean_subtype_checked!=null)
{
for (int i = 0; i < boolean_subtype_checked.length; i++)
{
boolean_subtype_checked[i]=false;
}
}


}
/**
* methods for fetching state as per selected city
* @param selected_country2
*/
protected void active_states(String selected_country2)
{
mCursor_states = mDatabaseConnectionAPI.ExecuteQueryGetCursor("SELECT "
+ mStaticValues.state_name + "," + mStaticValues.state_id
+ " FROM " + mStaticValues.state_master + " where "
+ mStaticValues.is_active + " ='Y' AND "
+ mStaticValues.country_id + "=( SELECT "
+ mStaticValues.country_id + " FROM "
+ mStaticValues.country_master + " where "
+ mStaticValues.country_name + "=\"" + selected_country
+ "\");");

if (mCursor_states.getCount() > 0) {

Log.d("data", "call");

state_array = new String[mCursor_states.getCount()];

for (int i = 0; i < mCursor_states.getCount(); i++) {
mCursor_states.moveToPosition(i);
state_array[i] = mCursor_states.getString(mCursor_states
.getColumnIndex(mStaticValues.state_name));

mCursor_states = mDatabaseConnectionAPI.ExecuteQueryGetCursor("SELECT "
+ mStaticValues.state_name + ","
+ mStaticValues.state_id + " FROM "
+ mStaticValues.state_master + " where "
+ mStaticValues.is_active + " ='Y';");

if (mCursor_states.getCount() > 0) {

mCursor_states.moveToFirst();
state_array = new String[mCursor_states.getCount()];

for (int j = 0; j < mCursor_states.getCount(); j++) {
mCursor_states.moveToPosition(j);
state_array[j] = mCursor_states
.getString(mCursor_states
.getColumnIndex(mStaticValues.state_name));

}

spiner_state_arrayAdapter = new ArrayAdapter<String>(
getApplicationContext(),
R.layout.text_data_simple_spinner, state_array);

if (spinner_state != null)
spinner_state.setAdapter(spiner_state_arrayAdapter);

spinner_state
.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(
AdapterView<?> parent, View view,
int position, long id) {
getStateId = mCursor_states.getPosition();
mCursor_states.moveToPosition(position);
selected_state = mCursor_states.getString(mCursor_states.getColumnIndex(mStaticValues.state_name)).toString();
selectedStateID = mCursor_states.getString(mCursor_states.getColumnIndex(mStaticValues.state_id)).toString();
}

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

}
else
{
mAllMethods.alertDialogForValidation(mActivity,
mStaticValues.MessageErrorTitle,
mStaticValues.NoActiveState,false);
spinner_state.invalidate();
}
}
}

mCursor_states.close();
}

/**
* method for search property
* @param mCursor_searchcode
*/
public void getproperty(Cursor mCursor_searchcode)
{
if(mCursor_searchcode.getCount()>0)
{
if(boolean_log_in)
{
mIntent.setClass(SearchProperty.this, ShowAreas.class);
RealEstateApplication.CURRENT_PURPOSE = mStaticValues.All;
RealEstateApplication.CURRENT_MODE = mStaticValues.SearchMode;
// mIntent.putExtra(mStaticValues.current_purpose, mStaticValues.All);
// mIntent.putExtra(mStaticValues.current_mode, mStaticValues.SearchMode);
startActivity(mIntent);
}

else
{
mIntent.setClass(SearchProperty.this, Login.class);
RealEstateApplication.CURRENT_MODE = mStaticValues.SearchMode;
// mIntent.putExtra(mStaticValues.current_mode, mStaticValues.SearchMode);
startActivity(mIntent);
}
}
else {
mAllMethods.alertDialogForValidation(mActivity,
mStaticValues.MessageErrorTitle,
mStaticValues.NoProperty,false);
}

}


// private int mSelected = -1;

/**
* method for fetch property type dialog
*/

public void proprtyTypedialog()
{
try
{

selected_type = "";
selectedPropertyTypeIDs="";
selectedPropertySubTypeIDs="";
// Log.d("GetCount Type :",
// String.valueOf(mCursor_property_type.getCount()));

final Builder build = new Builder(this);
build.setTitle(mStaticValues.TypeSelection);
build.setCancelable(true);
OnMultiChoiceClickListener onClick = new OnMultiChoiceClickListener()
{
@Override
public void onClick(final DialogInterface dialog,
final int which, final boolean isChecked)
{

if (isChecked)
{
if (boolean_type_checked[which])
{
final int oldVal = mSelected;
final AlertDialog alert = (AlertDialog) dialog;
final ListView list = alert.getListView();
list.setItemChecked(oldVal, false);
}
mSelected = which;
boolean_type_checked[which] = true;
}
else
{
boolean_type_checked[which] = false;
txt_property_type.setText("");
}
}
};

build.setMultiChoiceItems(getpropertysubId, boolean_type_checked, onClick);
build.setPositiveButton(mStaticValues.Done,
new DialogInterface.OnClickListener()
{

public void onClick(final DialogInterface dialog,
final int which)
{
txt_property_sub_type.setText("");

if (boolean_type_checked.length == -1)
Log.d("Selection", "You didn't select anything.");
else
{
for (int j = 0; j < getpropertysubId.length; j++)
{
if (boolean_type_checked[j])
{
Log.d("Checked",
getpropertysubId[j].toString());
selected_type = selected_type
+ "\'"
+ getpropertysubId[j]
                  .toString() + "\', ";

if(selectedPropertyTypeIDs.trim().length()>0)
{
selectedPropertyTypeIDs = selectedPropertyTypeIDs
+ ","
+ getListSelectedTypeIds[j].toString();
}
else
selectedPropertyTypeIDs =getListSelectedTypeIds[j].toString();
////System.out.println("WHITCH:" + which);

} else
Log.d("not Checked",
getpropertysubId[j].toString());
}
}
if (selected_type.length() > 0)
{

selected_type = (String) selected_type
.subSequence(0,
selected_type.length() - 2);

System.out.println("selectedPropertyTypeIDs "+selectedPropertyTypeIDs);

// selectedPropertyTypeIDs = (String)selectedPropertyTypeIDs.subSequence(0,selected_type.length() - 2);
// System.out.println("selectedPropertyTypeIDs "+selectedPropertyTypeIDs);
//
txt_property_type.setText(selected_type
.replaceAll("\'", ""));


mCursor_setTextData=mDatabaseConnectionAPI.setTextData(mStaticValues.property_type_master, selectedPropertyTypeIDs );
// mCursor_property_sub_type = mDatabaseConnectionAPI
// .ExecuteQueryGetCursor("Select "+ mStaticValues.type_name +" FROM "+ mStaticValues.property_type_master +" "
// + " WHERE "+ mStaticValues.parent_id+" in"
// + " (SELECT "+ mStaticValues.type_id +" FROM " + mStaticValues.property_type_master +" WHERE "+ mStaticValues.type_name +" in"
// + " ("
// + selected_type
// + ")) GROUP BY " + mStaticValues.type_name +" ");
mCursor_setTextData.moveToFirst();
getpropertysubId1 = new String[mCursor_setTextData
                              .getCount()];

getListSelectedSubTypeIds = new String[mCursor_setTextData
                                      .getCount()];

boolean_subtype_checked = new boolean[mCursor_setTextData
                                     .getCount()];
for (int i = 0; i < mCursor_setTextData
.getCount(); i++) {

mCursor_setTextData.moveToPosition(i);
getpropertysubId1[i] = mCursor_setTextData
.getString(mCursor_setTextData
.getColumnIndex(mStaticValues.type_name));
getListSelectedSubTypeIds[i]= mCursor_setTextData
.getString(mCursor_setTextData
.getColumnIndex(mStaticValues.type_id));
boolean_subtype_checked[i] = false;
txt_property_sub_type.setText("");
}
}
}
});
build.show();

} catch (Exception e) {
// e.printStackTrace();
}

}
public void propertySubTypeDialog()
{

try
{
selected_subtype = "";
selectedPropertySubTypeIDs="";

Log.d("GetCount Type :",
String.valueOf(mCursor_setTextData.getCount()));

final Builder build = new Builder(SearchProperty.this);
build.setTitle(mStaticValues.SubtypeSelection);
build.setCancelable(true);
OnMultiChoiceClickListener onClick = new OnMultiChoiceClickListener()
{
@Override
public void onClick(final DialogInterface dialog,
final int which, final boolean isChecked)
{
if (isChecked)
{
if (boolean_subtype_checked[which])
{
final int oldVal = mSelected;
final AlertDialog alert = (AlertDialog) dialog;
final ListView list = alert.getListView();
list.setItemChecked(oldVal, false);
}

mSelected = which;
boolean_subtype_checked[which] = true;
}

else
{  
boolean_subtype_checked[which] = false;
txt_property_sub_type.setText("");
}
}
};

build.setMultiChoiceItems(getpropertysubId1, boolean_subtype_checked,
onClick);
build.setPositiveButton("Done",
new DialogInterface.OnClickListener() {

public void onClick(final DialogInterface dialog,
final int which) {

if (boolean_subtype_checked.length != -1)
{ ////System.out.println("You Dont Selected Anything");
// else
for (int j = 0; j < getpropertysubId1.length; j++)
{
if (boolean_subtype_checked[j])
{
Log.d("Checked",
getpropertysubId1[j]
                 .toString());
selected_subtype = selected_subtype
+ "\'"
+ getpropertysubId1[j]
                   .toString() + "\', ";


if(selectedPropertySubTypeIDs.trim().length()>0)
{
selectedPropertySubTypeIDs = selectedPropertySubTypeIDs
+ ","
+ getListSelectedSubTypeIds[j].toString();
}
else
selectedPropertySubTypeIDs = getListSelectedSubTypeIds[j].toString();


////System.out.println("WHITCH:-" + which);
}
else
Log.d("not Checked",
getpropertysubId1[j]
                 .toString());
}
}

if (selected_subtype.length() > 0)
{
selected_subtype = (String) selected_subtype.subSequence(
0, selected_subtype.length() - 2);
System.out.println("selectedPropertySubTypeIDs " +selectedPropertySubTypeIDs);
txt_property_sub_type
.setText(selected_subtype
.replaceAll("\'", ""));
}


}
});
build.show();
}
catch (Exception e)
{
// e.printStackTrace();
}
}
@Override
protected void onResume()
{
view_visibility();
removeALLSelected();
super.onResume();
}
@Override
protected void onDestroy()
{
if(mDatabaseConnectionAPI!=null)
mDatabaseConnectionAPI.close();
super.onDestroy();
}


}