2

这是我的 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 文件,它工作正常,但是一旦我尝试使用该类正确执行它,它就不起作用,只是沿着行“这是一些文本\n这是一些更多。” 我的 textView 的文本由我的 adapter.class 中的这一行设置

date1.setText(song.get(CustomizedListView.KEY_DATE1));

CustomizedListView.class 只是设置 ListView 并为 Adapter 提供设置文本所需的字符串。有谁知道为什么通过类使用设置字符串不适用于\n?我听说上面的行必须以某种方式进行更改才能正常工作,但我不确定如何。感谢阅读和帮助。

适配器类

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

0 回答 0