gpt4 book ai didi

android - 除非在编辑文本中输入完整的行,否则搜索不会完成

转载 作者:行者123 更新时间:2023-11-29 01:23:07 24 4
gpt4 key购买 nike

我有一个新的搜索 Activity ,它有一个用于输入搜索查询的编辑文本和用于搜索 EditText 中输入的查询的搜索按钮

搜索到的项目显示在搜索 Activity 的 ListView

现在的问题是我有一个 ListView,用户可以从中搜索所需内容

让我们假设这个 ListView 有 100 个列表项,全部命名为 :

  1. 测试标题 1,
  2. 测试标题 2,
  3. 测试标题 3 ,
  4. 测试标题 4,

    依此类推直到测试标题 100

现在在 editext 的搜索 Activity 中,如果我输入“test”并按下搜索按钮,它应该显示所有列表,因为每个列表项标题的标题中都包含测试,但我什么也得不到

我必须输入整个标题才能完成搜索,例如“test heading 1”,匹配的标题会显示在列表中

如果我在 edittext 中输入“test”并按下搜索按钮,我怎样才能使搜索更好,它应该显示其标题中包含测试词的所有项目

this is the original list view which contains all the test headings

this is the search activity where i hae to enter the complete and correct list heading in order to perform search

现在我正在使用 parse.com 将数据检索到 ListView 中(遗憾的是 parse.com 正在关闭)并且我正在将我的数据库迁移到 m6 自己的服务器

我试过的代码

搜索 Activity

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();
}
}
});
}


}

});

}



}

第一个图像中 rhe 列表 Activity 的 aynctask

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
}
}

最佳答案

您正在使用 whereEqualTo() 它要求特定键的值等于提供的值。

query.whereEqualTo("listheading", seaechedit);

将其替换为 它会找到包含所提供字符串的字符串值。

query.whereContains("listheading", seaechedit);

参见whereContains Function

关于android - 除非在编辑文本中输入完整的行,否则搜索不会完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35595439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com