これが私の TextView で、複数の行が必要です
<TextView
android:id="@+id/date1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:textColor="#343434"
android:textSize="14sp"
android:layout_marginTop="1dip"
android:layout_toRightOf="@id/list_image"
android:layout_marginLeft="4dp"
android:maxLines="3"/>
この textView は ListView で使用されるため、Adapter.class を介してテキストを設定します。\n を含む文字列を追加するときに textView のスタイルを設定するために使用される個々の XML ファイルを見ると、正常に動作しますが、クラスを使用して適切に実行しようとするとすぐに動作せず、 「This is some text\nThis is some more.」の行。私のtextViewのテキストは、私のadapter.classのこの行によって設定されています
date1.setText(song.get(CustomizedListView.KEY_DATE1));
CustomizedListView.class は、ListView を設定するだけで、アダプタにテキストの設定に必要な文字列を提供します。クラスを介してセット文字列を使用しても \n が機能しない理由を知っている人はいますか? 上記の行を何らかの方法で変更して機能させる必要があると聞いたことがありますが、その方法はわかりません。読んで助けてくれてありがとう。
Adapter.class
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView)vi.findViewById(R.id.title); // title
TextView date1 = (TextView)vi.findViewById(R.id.date1);
TextView platforms = (TextView)vi.findViewById(R.id.platforms);
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
// Setting all values in listview
title.setText(song.get(CustomizedListView.KEY_TITLE));
date1.setText(song.get(CustomizedListView.KEY_DATE1));
platforms.setText(song.get(CustomizedListView.KEY_PLATFORMS));
imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
return vi;
}
}