我是新手。我正在编辑可搜索SDK上的Searchable Dictionary。 Dictionary遵循\ res \ raw \ definitions.txt
上的数据库搜索单词时显示结果(定义)如下 -
line1 line2 line3
但我想在结果上添加换行符并在下面显示(defination) -
line1
line2
line3
WordActivity.java的代码在这里
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.word);
Uri uri = getIntent().getData();
Cursor cursor = managedQuery(uri, null, null, null, null);
if (cursor == null) {
finish();
} else {
cursor.moveToFirst();
TextView word = (TextView) findViewById(R.id.word);
TextView definition = (TextView) findViewById(R.id.definition);
int wIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_WORD);
int dIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_DEFINITION);
word.setText(cursor.getString(wIndex));
definition.setText(cursor.getString(dIndex));
}}
public void onBackPressed() {
onSearchRequested();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// TODO Auto-generated method stub
case R.id.search:
onSearchRequested();
return true;
case R.id.about:
setContentView(R.layout.abouttanzil);
return true;
case R.id.exit:
moveTaskToBack(true);
return true;
default:
return false;
}
}
}
请让我知道我应该添加什么以及在哪里进行换行? 提前谢谢。
答案 0 :(得分:1)
将其显示为HTML并使用\ n。
yourTextView.setText(Html.fromHtml(someText + "\n" + someOtherText));
显然有更聪明的方法。只是向您展示Html.fromHtml()方法。