我正在使用一个 android 应用程序。在那,首先我需要存储来自 web 服务的所有数据,然后从 db 查询数据并在 listview 中更新。
我的列表视图项目包含复选框和按钮。当我单击按钮或复选框时,它工作正常(显示 LOG)但是当我单击列表视图中的按钮时我需要启动子活动。
这是我的适配器类,
public class GuestListAdapter extends BaseAdapter{
Context context;
ArrayList<String > arrayListFirstValue;
ArrayList<String > arrayListSecondValue;
ArrayList<String > arrayListThirdValue;
public GuestListAdapter(Context mcontext, ArrayList<String> arrListFV,ArrayList<String> arrListSV,ArrayList<String> arrListGuestTV)
{
arrayListFirstValue =arrListFV;
arrayListSecondValue =arrLisSV;
arrayListThirdValue =arrListTV;
context = mcontext;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return arrayListFirstValue.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return arrayListFirstValue.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
// TODO Auto-generated method stub
if (view == null) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
view = inflater.inflate(R.layout.guest_list_item, parent, false);
}
TextView txtFirstValue = (TextView)view.findViewById(R.id.txt_firstname);
txtFirstValue .setText(arrayListFirstValue.get(position));
TextView txtSecondValue = (TextView)view.findViewById(R.id.txt_lastname);
txtSecondValue .setText(arrayListSecondValue.get(position));
TextView txtThirdValue = (TextView)view.findViewById(R.id.txt_guest_count);
txtThirdValue .setText(arrayListThirdValue.get(position));
Button btnInfo = (Button)view.findViewById(R.id.btn_info);
CheckBox checkBoxCheckins = (CheckBox)view.findViewById(R.id.checkBoxIsCheckedIn);
btnInfo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Adap button **********");
}
});
checkBoxCheckins.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
System.out.println("Adap checked **********");
}
});
return view;
}
}
最后我的问题是当我单击列表视图中的按钮时我需要启动子活动。请告诉我如何实现这一目标。