我从sqlite数据库获取文本列表,并在自定义列表视图中显示它们。我在数据库中的文本示例如下:
你好
你有吗?
但是当我从数据库中获取此文本并将其显示在自定义列表视图中时,它显示如下: 哈Have,你好吗? 我的文字显示为单行!如何多行显示? 什么问题?! 这是我的示例代码:
final SQLiteDatabase mydb = new MyDatabase2(EnglishActivity.this).getWritableDatabase();
Cursor cT=mydb.rawQuery(" SELECT * FROM "+ TABLE + " WHERE "
+ TITLE + " LIKE ? " ,new String []{inputSearch.getText()+"%"});
array = new String[cT.getCount()];
int i = 0;
while(cT.moveToNext()){
String uname = cT.getString(cT.getColumnIndex(TITLE)); array[i] = uname;
i++;
}
lv.setAdapter( new EnCustomAdapter(EnglishActivity.this,array,tf));
我的自定义适配器:
public class EnCustomAdapter extends BaseAdapter {
Context context;
String[] Maany;
Typeface tff;
private static LayoutInflater inflater=null;
public EnCustomAdapter(Activity mainActivity, String[] maany, Typeface tf) {
tff=tf;
context=mainActivity;
Maany=maany;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return result.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public class Holder
{
TextView tv1;
Typeface t;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.list_item_english, null);
holder.tv=(TextView) rowView.findViewById(R.id.txtFa);
holder.tv.setText(Maany[position]);
holder.tv.setTypeface(tff);
return rowView;
}
}
答案 0 :(得分:0)
在数据库中,将数据另存为:
Hello\nHave are you?
在任何希望出现在新行上的行中包括\n