从Cursor到一个listview元素的Concat结果

| 我有一个android listview,它具有two_line_list_item布局。...text1和text2 我有一个SQL查询,它返回我的Cursor ....在下面的示例中,我将NameA从SQL设置为text1,将NameB设置为text2。
        // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[]{\"NameA\", \"NameB\"};

    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{android.R.id.text1, android.R.id.text2};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter matches = new SimpleCursorAdapter(this, android.R.layout.two_line_list_item, MatchesCursor, from, to);
    setListAdapter(matches);
我该如何串联两个名称(不更改我的SQL查询),以便text1为\“ NameA v NameB \” ... 提前致谢     
已邀请:
        在您的查询中
NameA || \"v\" || NameB AS NameAB
然后删除第二个textView(android.R.text2) 在返回投影中,将\“ NameAB \”放在其他列中(保留KEY_ID),因为您将不再需要它们。     
        在我看来,您需要编写扩展BaseAdapter的自定义适配器。     
        一种肮脏的方式是在xml中使用3个视图:
<TextView
        android:id=\"@+id/nameA\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:textSize=\"30dp\" />
<TextView
        android:id=\"@+id/separator\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:text=\" vs \"
        android:textSize=\"30dp\" />
<TextView
        android:id=\"@+id/nameB\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:textSize=\"30dp\" />
将所有内容包装在水平LinearLayout中。     
        您需要编写扩展
BaseAdapter
的自己的适配器
public class CustomAdapter extends BaseAdapter {

    private Context context;
    private int listItemLayout;
    private String[] nameAs;
    private String[] nameBs;

    public CustomAdapter(Context context, int listItemLayout, String[] nameAs, String[] nameBs) {
        this.context = context;
        this.listItemLayout = listItemLayout;
        this.nameAs = nameAs;
        this.nameBs = nameBs;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if(convertView==null)
            convertView = LayoutInflater.from(context).inflate(listItemLayout, null);

            TextView textView1 = (TextView)findViewById(android.R.id.text1);
            textView1.setText(nameAs[position] + \" v \" + nameBs[position]);
        return convertView;
    }

}
现在,您需要做的就是修改数据库访问函数的一部分,以返回两个名称数组,并将它们传递给ѭ5the的构造函数。 最后,致电:
CustomAdapter myAdapter = new CustomAdapter(this, android.R.layout.two_line_list_item, nameAs, nameBs);
setListAdapter(myAdapter);
请注意,也请尝试遵循链接中建议的ViewHolder模式。     

要回复问题请先登录注册