Android listview 变成 checkbox listview

文章标签: android,android-listview
2014-12-18 9:10:06     人阅读    

入行android一个月...但是依然是一个码农....
我现在有一个listview,是别人写的,展示从数据库中查询出来的数据,我想把listView换成   checkbox listview,我不知道如何改...下面是我listView的代码

public class StudentDetailActivity extends Activity implements OnClickListener, OnItemClickListener {

    private ListView uGraduateNamesListView;
    private Button addNewUndergraduateButton;

        private ListAdapter uGraduateListAdapter;


    private ArrayList<UndergraduateDetailsPojo> pojoArrayList;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_student_detail);


        uGraduateNamesListView = (ListView) findViewById(R.id.uGraduateListView);
        uGraduateNamesListView.setOnItemClickListener(this);

        addNewUndergraduateButton = (Button) findViewById(R.id.namesListViewAddButton);
        addNewUndergraduateButton.setOnClickListener(this);

        pojoArrayList = new ArrayList<UndergraduateDetailsPojo>();


        uGraduateListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());

        uGraduateNamesListView.setAdapter(uGraduateListAdapter);

    }



    public List<String> populateList(){

                List<String> uGraduateNamesList = new ArrayList<String>();

                AndroidOpenDbHelper openHelperClass = new AndroidOpenDbHelper(this);


        SQLiteDatabase sqliteDatabase = openHelperClass.getReadableDatabase();


        Cursor cursor = sqliteDatabase.query(AndroidOpenDbHelper.TABLE_NAME_GPA, null, null, null, null, null, null);

        startManagingCursor(cursor);

                while (cursor.moveToNext()) {


            String ugName = cursor.getString(cursor.getColumnIndex(AndroidOpenDbHelper.COLUMN_NAME_UNDERGRADUATE_NAME));
            String ugUniId = cursor.getString(cursor.getColumnIndex(AndroidOpenDbHelper.COLUMN_NAME_UNDERGRADUATE_UNI_ID));
            double ugGpa = cursor.getDouble(cursor.getColumnIndex(AndroidOpenDbHelper.COLLUMN_NAME_UNDERGRADUATE_GPA));

                        UndergraduateDetailsPojo ugPojoClass = new UndergraduateDetailsPojo();
            ugPojoClass.setuGraduateName(ugName);
            ugPojoClass.setuGraduateUniId(ugUniId);
            ugPojoClass.setuGraduateGpa(ugGpa);


            pojoArrayList.add(ugPojoClass);


            uGraduateNamesList.add(ugName);
        }


        sqliteDatabase.close();

        return uGraduateNamesList;
    }


    @Override
    protected void onResume() {
        super.onResume();
        pojoArrayList = new ArrayList<UndergraduateDetailsPojo>();
        uGraduateListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
        uGraduateNamesListView.setAdapter(uGraduateListAdapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
        pojoArrayList = new ArrayList<UndergraduateDetailsPojo>();
        uGraduateListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, populateList());
        uGraduateNamesListView.setAdapter(uGraduateListAdapter);
    }


    }
}

下面是我 listview 布局文件

<ListView
    android:id="@+id/uGraduateListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/namesListViewAddButton"
    android:layout_alignLeft="@+id/namesListViewAddButton"
    android:layout_alignParentTop="true" >

</ListView>

希望有人可以帮忙一下,告诉如何修改..

 

处理方法

uGraduateListAdapter = new ArrayAdapter<String>(this, 
android.R.layout.simple_list_item_checked, populateList());

修改

uGraduateListAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, populateList());


换成


xml 文件修改

android:choiceMode="multipleChoice"


原文地址:http://www.itmmd.com/201412/335.html
该文章由 萌萌的IT人 整理发布,转载须标明出处。

Stop service in an activity   上一篇
下一篇  Jquery Ajax 之 Web Service调用与安全
精彩回复
我要追加问题,请求站长解决!
姓名:       

《程序员app》专门为程序员量身定做!