网络上的那个东西似乎都不准,以下是我做的此方法为可行。
首先,
main.xml
- "1.0" encoding="utf-8"?>
- ""
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- android:id="@+id/listView1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" >
-
-
然后list.xml
- "1.0" encoding="utf-8"?>
- ""
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- android:id="@+id/_id"
- android:visibility="gone"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:text="TextView" />
- android:id="@+id/checkText"
- android:layout_width="fill_parent"
- android:layout_height="?android:attr/listPreferredItemHeight"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:gravity="center_vertical"
- android:checkMark="?android:attr/listChoiceIndicatorMultiple"
- android:paddingLeft="6dip"
- android:paddingRight="6dip"
- />
-
以下是自定义组件。
- public final class Compan {
- public TextView id;
- public CheckedTextView ctv;
- }
public final class Compan {
public TextView id;
public CheckedTextView ctv;
}
自定义adapter方法
- package com.duduli.li;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.content.Context;
- import android.database.Cursor;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- import android.widget.AdapterView;
- import android.widget.CheckedTextView;
- import android.widget.SimpleCursorAdapter;
- import android.widget.TextView;
- public class MyAdapter extends SimpleCursorAdapter{
- private List list = new ArrayList();
- public String s[];
- private List
- private LayoutInflater layoutInflater;
- private List delNumber = new ArrayList();
- @SuppressWarnings("unused")
- private Context context;
- public MyAdapter(Context context, int layout, Cursor c,
- String[] from, int[] to) {
- super(context, layout, c, from, to);
- this.context = context;
- this.data = getData();
- this.layoutInflater = LayoutInflater.from(context);
- }
- @Override
- public int getCount() {
- return super.getCount();
- }
- @Override
- public Object getItem(int position) {
- return super.getItem(position);
- }
- @Override
- public long getItemId(int position) {
- return super.getItemId(position);
- }
- @SuppressWarnings("unused")
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- Compan cp = null;
- if(cp == null){
- cp = new Compan();
- convertView = layoutInflater.inflate(R.layout.list, null);
- cp.id = (TextView) convertView.findViewById(R.id._id);
- cp.ctv = (CheckedTextView) convertView.findViewById(R.id.checkText);
- convertView.setTag(cp);
- }else{
- cp = (Compan) convertView.getTag();
- }
- cp.id.setText((CharSequence) data.get(position).get("_id"));
- cp.ctv.setText((CharSequence) data.get(position).get("Number"));
- return convertView;
- }
- public List
- Listnew ArrayList
- while (getCursor().moveToNext()) {
- Map map = new HashMap();
- map.put("_id", getCursor().getString(0));
- map.put("Number", getCursor().getString(1));
- list.add(map);
- }
- return list;
- }
- }
package com.duduli.li;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CheckedTextView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class MyAdapter extends SimpleCursorAdapter{
private List list = new ArrayList();
public String s[];
private List
阅读(820) | 评论(0) | 转发(0) |