CursorAdapter的一段代码

实现了一个用于显示Android设备上最近通话记录的活动,包括编辑、全选、取消选择和删除功能。
import android.app.Activity;
import android.content.AsyncQueryHandler;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog.Calls;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TextView;


public class RecentCallsListActivity extends Activity {
    /** Called when the activity is first created. */
private LinearLayout mEditLinearLayout;
private Button mAllSelectButton;
private Button mCancelSelectedButton;
private Button mDeleteButton;
private ListView mListView;
private TextView mEmptyTextView;
private QueryHandler mQueryHandler;
private RecentCallsListAdapter mAdapter;

private final static String[] CALLS_PROJECTION = new String[]{Calls._ID,Calls.NUMBER,Calls.DATE,
                                            Calls.CACHED_NAME,Calls.TYPE}; 
private final static int ID_COLUMN_INDEX = 0;
private final static int NUMBER_COLUMN_INDEX = 1;
private final static int DATE_COLUMN_INDEX = 2;
private final static int CACHED_NAME_COLUMN_INDEX = 3;
private final static int TYPE_COLUMN_INDEX = 4;

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


private void initView() {
mEditLinearLayout = (LinearLayout) findViewById(R.id.edit);
mAllSelectButton = (Button) findViewById(R.id.button_allSelect);
mCancelSelectedButton = (Button) findViewById(R.id.button_cancelSelected);
mDeleteButton = (Button) findViewById(R.id.button_delete);
mListView = (ListView) findViewById(R.id.listView);
mEmptyTextView = (TextView) findViewById(R.id.emptyTextView);

mEditLinearLayout.setVisibility(View.GONE);
mDeleteButton.setVisibility(View.GONE);

mQueryHandler = new QueryHandler(getContentResolver());
mAdapter = new RecentCallsListAdapter(this, null);
mListView.setEmptyView(mEmptyTextView);
mListView.setAdapter(mAdapter);


startQuery();
}

private void startQuery(){
mQueryHandler.startQuery(0, null, Calls.CONTENT_URI, CALLS_PROJECTION, null, null, Calls.DEFAULT_SORT_ORDER);
}

final class RecentCallsListViews{
CheckBox mChechBox ;
ImageView mHeaderImageView;
TextView mNameTextView;
TextView mNumberTextView;
TextView mDateTextView;
TableLayout mTableLayout;
ImageView mCallTypeImage;

}
    class RecentCallsListAdapter extends CursorAdapter{


public RecentCallsListAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}


@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = LayoutInflater.from(RecentCallsListActivity.this);
View view = inflater.inflate(R.layout.call_list_item, parent);
RecentCallsListViews views = new RecentCallsListViews();
views.mChechBox = (CheckBox) view.findViewById(R.id.mCheckbox);
views.mHeaderImageView = (ImageView) view.findViewById(R.id.mHeaderImageView);
views.mNameTextView = (TextView) view.findViewById(R.id.name);
views.mNumberTextView = (TextView) view.findViewById(R.id.number);
views.mDateTextView = (TextView) view.findViewById(R.id.date);
views.mTableLayout = (TableLayout) view.findViewById(R.id.call);
view.setTag(views);
return view;
}


@Override
public void bindView(View view, Context context, Cursor cursor) {
// TODO Auto-generated method stub
if(null == cursor || cursor.getCount() < 1){
return;
}

}

}

final class QueryHandler extends AsyncQueryHandler{


public QueryHandler(ContentResolver cr) {
super(cr);
// TODO Auto-generated constructor stub
}

@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
// TODO Auto-generated method stub
super.onQueryComplete(token, cookie, cursor);
mAdapter.changeCursor(cursor);
}

}
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值