本文介绍了SimpleCursorAdapter - 设置2列1视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQLite数据库建设从我的的ListView SimpleCursorAdapter 显示数据。我有2列,但我想displey它们在1 的TextView 。我该怎么办呢?谢谢

I have a SQLite Datebase from which I am displaying data in ListView by SimpleCursorAdapter. I have 2 columns but I want to displey them in 1 TextView. How can I do that? Thanks

推荐答案

试试这个code,它可以帮助你。

Try This Code , it may help you

方法调用从OnCreate中列表视图

Method For calling Listview from Oncreate

private void populateListViewFromDB1()
                {
                    Cursor cursor = helper1.getAllData(Sharedemail);



                            startManagingCursor(cursor);

                            String[] productname = new String[]
                                    {
                                    DataBaseHelper.KEY_NAMEVALUE,
                                    DataBaseHelper.KEY_TYPE,


                                    };

                            int[] viewproduct = new int[]
                                    {
                                    R.id.textView1,
                                    };

                            // Create Adapter 
                              MySimpleCursoradapter myCursorAdapter = new MySimpleCursoradapter
                                      (this,
                                       R.layout.listview,
                                       cursor,
                                       productname,
                                       viewproduct);


                            ListView List = (ListView) findViewById(R.id.listView1);
                            List.setAdapter(myCursorAdapter);
                       }


                }

MySimpleCursoradapter.java

MySimpleCursoradapter.java

public class MySimpleCursoradapter extends SimpleCursorAdapter {

public MySimpleCursoradapter(Context context, int layout,
            Cursor cur, String[] from, int[] to) {
        super(context, layout, cur, from, to);

    }

    @SuppressWarnings("static-access")
    @Override
    public View newView(Context con, Cursor c, ViewGroup arg2) {

        LayoutInflater inflater = (LayoutInflater) con
                .getSystemService(con.LAYOUT_INFLATER_SERVICE);

        View retView = inflater.inflate(R.layout.listview, null);

        return retView;
    }

public void bindView(View v, Context context, Cursor c) {

        String pname = c.getString(c.getColumnIndex(DataBaseHelper.KEY__NAMEVALUE));
        String issuetype = c.getString(c.getColumnIndex(DataBaseHelper.KEY_TYPE));

    TextView name_text = (TextView) v.findViewById(R.id.textView1);

name_text.setText(pname +":"+ issuetype);


}

}

这篇关于SimpleCursorAdapter - 设置2列1视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 17:19