如何将SearchView用于印地语ListView



我的ListView中有一个SearchView,它是印地语的。。当我使用搜索输入hindi时,它会很好地过滤列表。。

当用户在英文中搜索时,我想获得过滤列表

例如,如果用户搜索"Mangal">,则应筛选包含的列表मंगल

以下是我的主要活动类

public class MainActivity extends AppCompatActivity implements SearchView.OnQueryTextListener {
// Declare Variables
ListView list;
ListViewAdapter adapter;
SearchView editsearch;
String[] NameList;
ArrayList<Names> arraylist = new ArrayList<Names>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Generate sample data
NameList = new String[]{"मंगल स्तुति", "भिक्षु स्तुति", "कालू स्तुति",
"तुलसी स्तुति", "महाप्रज्ञ अभिवंदना", "शासन स्तुति", "तपस्या गीत"};
// Locate the ListView in listview_main.xml
list = (ListView) findViewById(R.id.listview);
for (int i = 0; i < NameList.length; i++) {
Names Names = new Names(NameList[i]);
// Binds all strings into an array
arraylist.add(Names);
}
// Pass results to ListViewAdapter Class
adapter = new ListViewAdapter(this, arraylist);
// Binds the Adapter to the ListView
list.setAdapter(adapter);
// Locate the EditText in listview_main.xml
editsearch = (SearchView) findViewById(R.id.search);
editsearch.setOnQueryTextListener(this);
}

@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
String text = newText;
adapter.filter(text);
return false;
}
}

我想用getQuery来获取搜索到的文本,然后将其与英文版本进行比较,但这将是非常立方体的,因为我的ListView上有很多印地语文本。。

此外,如果有可能为列表中的项目设置搜索标签。。我不确定。。。

请帮忙。。。

我强烈建议您阅读这些文档https://developer.android.com/studio/write/translations-editor

为了给您一个概述,您需要为应用程序中的每个字符串创建一个字符串资源。因此,将它们添加到您的Strings.xml中。类似于Mangal

下一步是通过单击"打开编辑器"从strings.xml打开"翻译编辑器"。单击全局按钮,然后从中选择印地语。在翻译字段中添加翻译。对所有字段执行相同操作。现在用英语进行所有搜索。将设备语言更改为印地语。运行应用程序,您应该会看到应用程序的翻译字符串。

希望这能有所帮助。

最新更新