基本上,我有家具类型,家具颜色,家具尺寸,家具成本和家具材料。现在我有组合框显示各种可能的值来选择。在所有组合框中,我还输入了一个名为“all”的值,因为用户不希望以特定方式进行过滤。 现在我想根据用户的意见搜索家具。
但由于名为“all”的值,我面临很多问题。 所以我需要从前一个查询的结果中激活查询,以便我可以在php文件中保留条件,如果值不是“all”,那么查询应该执行。
请帮帮我..
Search_Furniture.java文件
public class Search_Furniture extends Activity
{
Spinner type,color,cost,size,material;
String atype, acolor, acost, asize, amaterial;
Button search;
List<String> l2;
JsonParser jsonparser = new JsonParser();
ProgressDialog pDialog;
private static final String loginUrl = "http://realroom.byethost24.com/realroom/search.php";
private static final String success = "success";
private static final String message = "message";
ArrayAdapter<String> adp2;
int pos;
SessionManager session;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.search_furniture);
session = new SessionManager(getApplicationContext());
type = (Spinner) findViewById(R.id.fur_type);
cost = (Spinner) findViewById(R.id.price);
color = (Spinner) findViewById(R.id.fur_color);
size = (Spinner) findViewById(R.id.fur_size);
search = (Button) findViewById(R.id.search);
material = (Spinner) findViewById(R.id.fur_mat);
type.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3)
{
// TODO Auto-generated method stub
pos=arg2;
add();
}
private void add()
{
// TODO Auto-generated method stub
switch(pos)
{
case 0:
l2= new ArrayList<String>();
l2.add("All");
adp2=new ArrayAdapter<String>(Search_Furniture.this,R.layout.spinner_item ,l2);
adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
size.setAdapter(adp2);
break;
case 1:
l2= new ArrayList<String>();
l2.add("All");
l2.add("2-Sit");
l2.add("3-Sit");
l2.add("L-Shape");
l2.add("Sofa+Chair");
adp2=new ArrayAdapter<String>(Search_Furniture.this,R.layout.spinner_item ,l2);
adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
size.setAdapter(adp2);
// select();
break;
case 2:
l2= new ArrayList<String>();
l2.add("All");
l2.add("2*2");
l2.add("3*3");
l2.add("4*4");
adp2=new ArrayAdapter<String>(Search_Furniture.this,R.layout.spinner_item,l2);
adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
size.setAdapter(adp2);
// select();
break;
case 3:
l2= new ArrayList<String>();
l2.add("All");
adp2=new ArrayAdapter<String>(Search_Furniture.this,R.layout.spinner_item,l2);
adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
size.setAdapter(adp2);
// select();
break;
case 4:
l2= new ArrayList<String>();
l2.add("All");
l2.add("Jumbo");
l2.add("King Size");
l2.add("Double Bed");
l2.add("Single Bed");
adp2=new ArrayAdapter<String>(Search_Furniture.this,R.layout.spinner_item,l2);
adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
size.setAdapter(adp2);
// select();
break;
case 5:
l2= new ArrayList<String>();
l2.add("All");
l2.add("Single");
l2.add("Double");
adp2=new ArrayAdapter<String>(Search_Furniture.this,R.layout.spinner_item,l2);
adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
size.setAdapter(adp2);
// select();
break;
case 6:
l2= new ArrayList<String>();
l2.add("All");
l2.add("4-Sitter");
l2.add("6-Sitter");
l2.add("8-Sitter");
l2.add("10-Sitter");
adp2=new ArrayAdapter<String>(Search_Furniture.this,R.layout.spinner_item,l2);
adp2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
size.setAdapter(adp2);
// select();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0)
{
// TODO Auto-generated method stub
}
});
search.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
new Search().execute();
// Intent i = new Intent(Search_Furniture.this,Items.class);
// startActivity(i);
}
});
}
/* (non-Javadoc)
* @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
*/
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowup = getMenuInflater();
blowup.inflate(R.menu.menu, menu);
return true;
}
/* (non-Javadoc)
* @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
*/
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// TODO Auto-generated method stub
Intent i;
switch(item.getItemId())
{
case R.id.checkout:
i = new Intent(Search_Furniture.this, MyCart.class);
startActivity(i);
break;
case R.id.aboutUs:
i = new Intent(Search_Furniture.this,AboutUs.class);
startActivity(i);
break;
case R.id.profile:
i = new Intent(Search_Furniture.this,Profile.class);
startActivity(i);
break;
case R.id.help:
i = new Intent(Search_Furniture.this,Help.class);
startActivity(i);
break;
case R.id.logout:
session.logoutUser();
break;
}
return false;
}
class Search extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
pDialog=new ProgressDialog(Search_Furniture.this);
pDialog.setMessage("Customizing your Furniture");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... params)
{
String atype = type.getSelectedItem().toString();
String acost = cost.getSelectedItem().toString();
String acolor = color.getSelectedItem().toString();
String asize = size.getSelectedItem().toString();
String amaterial = material.getSelectedItem().toString();
try {
List<NameValuePair> para = new ArrayList<NameValuePair>();
para.add(new BasicNameValuePair("f_type", atype));
para.add(new BasicNameValuePair("f_cost", acost));
para.add(new BasicNameValuePair("f_color", acolor));
para.add(new BasicNameValuePair("f_size", asize));
para.add(new BasicNameValuePair("f_material", amaterial));
System.out.println(atype);
System.out.println(acost);
System.out.println(acolor);
System.out.println(asize);
System.out.println(amaterial);
Log.d("request!", "starting");
JSONObject json = jsonparser.makeHttpRequest(loginUrl, "POST", para);
Log.d("Create response", json.toString());
int res = json.getInt(success);
if (res == 1)
{
Intent i =new Intent(Search_Furniture.this, Furniture.class);
startActivity(i);
// Log.d("User Created!", json.toString());
finish();
return json.getString(message);
}
}
catch (JSONException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String file_url)
{
pDialog.dismiss();
}
}
}
如何在mysql中为上述工具编写php查询.. ??
或者我可以通过其他方式在我的应用程序中提供此功能.. ??