我有一个新的搜索活动,其中有一个editext用于输入搜索查询和搜索按钮,用于搜索EditText
搜索的项目显示在搜索活动的ListView
现在问题是我有ListView
用户搜索所需的内容
让我们假设这个列表视图有100个列表项,所有列名都是 :
测试标题4,
依此类推至测试标题100
如果我输入"现在在editext的搜索活动中测试"并按下搜索按钮它应显示所有列表,因为每个列表项标题在其标题中包含测试但我什么都没得到
我必须输入搜索的整个标题才能完成#34; 测试标题1 "匹配的标题显示在列表
中如果我输入"我怎样才能使搜索更好测试"在edittext中按下搜索按钮,它应显示标题中包含测试词的所有项目
目前我正在使用parse.com将数据检索到listview(而且悲伤thar parse.com正在关闭)我正在将我的数据库迁移到m6自己的服务器
我尝试过的代码
搜索活动
public class SearchActivity extends Activity
{
protected EditText searchedittext;
Button searchButton;
List<ParseObject> ob;
@Override
public void onCreate(Bundle savedInstanceState )
{
// TODO: Implement this method
super.onCreate(savedInstanceState);
setContentView(R.layout.search_layout);
searchedittext = (EditText) findViewById(R.id.search_layoutEditText);
final ListView searchedlist = (ListView) findViewById(R.id.searchlist);
searchButton = (Button) findViewById(R.id.searchlayoutbtn);
searchButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
String seaechedit = searchedittext.getText().toString();
if(seaechedit.isEmpty()){
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
builder.setMessage("PLEASE ENTER SOME SEARCH QUERY")
.setTitle("EMPTY SEARCH")
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
else{
setProgressBarIndeterminateVisibility(true);
// InterActivity is the class name in parse database where listview retrives it data from
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"InterActivity");
query.whereEqualTo("listheading", seaechedit);
query.orderByAscending("_created_at");
query.setLimit(200);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> p1, ParseException e)
{
setProgressBarIndeterminateVisibility(false);
if(e == null){
ob = p1;
String [] searchHeadings = new String[ob.size()];
int i = 0;
// listheading is the coloumn name in parse database
for(ParseObject heading : ob){ searchHeadings[i] = (String) heading.get("listheading");
i++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>( SearchActivity.this, android.R.layout.simple_list_item_1, searchHeadings );
searchedlist.setAdapter(adapter);
}else{
Log.e("searchactivity", e.getMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(SearchActivity.this);
builder.setMessage(e.getMessage())
.setTitle("Nothing found")
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
}
});
}
}
第一张图片中列表活动的异常
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new SpotsDialog(InterActivity.this, R.style.Custom);
dialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create the array
codelist = new ArrayList<CodeList>();
try {
// Locate the class table named "Country" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"InterActivity");
// Locate the column named "ranknum" in Parse.com and order list
// by ascending
query.orderByAscending("_created_at");
query.setLimit(limit);
ob = query.find();
for (ParseObject inter : ob) {
map.setDescription((String) inter.get("subheading"));
map.setIntroduction((String) inter.get("intro"));
codelist.add(map);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (SwipeMenuListView) findViewById(R.id.inter_layoutListView);
// Pass the results into ListViewAdapter.java
adapter = new FinalAdapter(InterActivity.this,
codelist);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
listview.setOnItemClickListener(InterActivity.this);
dialog.dismiss();
}
@Override
public void onItemClick(AdapterView<?> p1, View view, int position, long p4)
{
ObjectMapper mapper = new ObjectMapper();
CodeList codes = (CodeList) adapter.getItem(position);
try{
Intent intent = new Intent(InterActivity.this, SingleItemView.class);
String jsonString = mapper.writeValueAsString(codes);
intent.putExtra("selected item", jsonString);
intent.putExtra("subheading",
(codelist.get(position).getDescription()));
intent.putExtra("intro",
(codelist.get(position).getIntroduction()));
// Start SingleItemView Class
// startActivity(intent);
startActivityForResult(intent, 1);
}catch(JsonProcessingException e){
//something went w3ong
}
}
答案 0 :(得分:1)
您正在使用whereEqualTo()
,它要求特定键的值等于提供的值。
query.whereEqualTo("listheading", seaechedit);
将其替换为,找到包含提供的字符串的字符串值。
query.whereContains("listheading", seaechedit);