我有一个列表视图,其中包含标题名称,ID和电话号码
随着我有复选框列表,我想要的是当我检查相应行的复选框时,它选择相应行的ID和名称,并通过点击菜单将数据传递到其他页面。
要做的步骤
1.检查多个复选框
2.通过计算列表视图中选中的复选框的数量
3.然后通过该页面上的点击菜单按钮将每个对应行的数据发送到下一页
我该怎么做?任何人都可以给我这些想法:)
private class SummaryAdapter extends ArrayAdapter<Item>{
private ArrayList<Item> items;
public SummaryAdapter(Context context,int textViewResourceId,ArrayList<Item> items){
super(context,textViewResourceId,items);
this.items=items;
}
public View getView(int position,View convertView,ViewGroup parent){
View v=convertView;
if(v==null){
LayoutInflater vi=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v=vi.inflate(R.layout.item,null);
}
Item o=items.get(position);
if(o!=null){
final TextView idView=(TextView)v.findViewById(R.id.itemId);
final TextView captionView=(TextView)v.findViewById(R.id.itemCaption);
final TextView phoneView=(TextView)v.findViewById(R.id.itemPhone);
final TextView typeView=(TextView)v.findViewById(R.id.itemType);
chkReport=(CheckBox)v.findViewById(R.id.chkReport);
//TextView t5=(TextView)v.findViewById(R.id.AdvanceSearchVisitID);
chkReport.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
if(idView!=null){
idView.setText(""+o.getId());
}
if(captionView!=null){
captionView.setText(o.getCaption());
}
if(phoneView!=null){
phoneView.setText(o.getPhone());
}
if(typeView!=null){
typeView.setText(o.getType());
}
captionView.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
fnNameClicked(idView.getText().toString(),typeView.getText().toString());
}
});
/* chkReport.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton arg0,boolean arg1) {
if(arg0.isChecked()){
fnCheckChanged(idView.getText().toString(),captionView.getText().toString(),arg1,arg0);
}
}
});*/
}
return v;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean result=super.onCreateOptionsMenu(menu);
menu.add(0,menu_1,1,R.string.menu_track_sales_force);
menu.add(0,menu_2,2,R.string.menu_select_all);
menu.add(0,menu_3,3,R.string.menu_unselect_all);
return result;
}
@
Override
public boolean onOptionsItemSelected(MenuItem item){
switch(item.getItemId()){
case menu_1:
//fnSave();
boolean bFlg=false;
boolean bMobile=false;
String sPhoneMsg="";
Integer listCount=lv.getCount();
Integer iListCount=0;
if(bNoMoreRecords==true){
iListCount=listCount;
}
else{
iListCount=listCount-1;
}
for(Integer xx=0;xx<iListCount;xx++){
if(lv.isItemChecked(xx)){
bFlg=true;
if("".equals(m_result.get(xx).getId())){
sPhoneMsg="Id of user "+m_result.get(xx).getCaption().toString()+" is not available, please remove it from selection.";
bMobile=true;
break;
}
}
}
if(bMobile==true){
MsgBox1(ctx,sPhoneMsg);
return true;
}
if(bFlg==false){
MsgBox1(ctx,"Please select atleast one ID !");
return true;
}
StringBuffer sb=new StringBuffer("");
SparseBooleanArray checkedItems=lv.getCheckedItemPositions();
int checkedItemsCount=checkedItems.size();
if(bNoMoreRecords==false){
if(listCount==checkedItemsCount){
checkedItemsCount=checkedItemsCount-1;
}
}
boolean isFirstSelected = true;
for (int i = 0; i < checkedItemsCount; ++i) {
int position = checkedItems.keyAt(i);
boolean isChecked = checkedItems.valueAt(i);
if(isChecked){
if(!isFirstSelected){
sb.append(", ");
}
if("".equals(m_result.get(position).getId())){}
else{
sb.append(m_result.get(position).getId());
}
isFirstSelected=false;
}
}
String ss=sb.toString();
Intent intent=new Intent(this,SRSDTrackForceDetails.class);
intent.putExtra("UserID",ss);
startActivity(intent);
//StringBuffer sb=new StringBuffer("Selection: ");
// SparseBooleanArray checkedItems=lv.getCheckedItemPositions();
//if (checkedItems==null || checkedItems.size()==0){
// MsgBox2(ctx,"Please select atleast one ID !");
//Toast.makeText(this, "Please select atleast one ID !", Toast.LENGTH_LONG).show();
// return true;
MsgBox1(ctx,"Tracking queried successfully !");
//Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();
return true;
case menu_2:
fnSelectAll();
return true;
case menu_3:
fnUnSelectAll();
return true;
}
return super.onOptionsItemSelected(item);
}
private void fnSelectAll(){
Integer listCount=lv.getCheckedItemPosition();
//listView.getCheckedItemPositions();
for(Integer xx=0;xx<listCount;xx++){
lv.setItemChecked(xx,true);
}
//listView
}
private void fnUnSelectAll(){
Integer listCount=lv.getCheckedItemPosition();
//listView.getCheckedItemPositions();
for(Integer xx=0;xx<listCount;xx++){
lv.setItemChecked(xx,false);
}
//listView
}
答案 0 :(得分:0)
这里的问题是什么。只需要一个与列表大小相同的标志数组。此布尔数组将包含列表中每个项的已检查状态。单击菜单按钮,只需遍历此数组,并在值true上将列表项(id,name)添加到临时arraylist或arrayList,并将该列表放在intent上,启动另一个活动。
答案 1 :(得分:0)
这会对你有所帮助:
http://www.vogella.de/articles/AndroidListView/article.html
在指数下
7.2。行与数据模型交互