0

我有一个列表视图,我的列表视图包含 3 个元素,两个文本视图和一个复选框,我的所有复选框默认为 true。现在,当我单击列表上的提交按钮时,我想获取所有选中的项目对应的文本视图信息,但我获取了在屏幕上可见的文本视图信息,但我的列表很长,所以我必须获取与其复选框对应的所有文本视图信息已检查,所以请帮我这样做。帮手肯定会得到一些奖励。

public class SendContactActivity extends Activity{
private Button cancelinfobtn,shareinfobtn;
private ListView user_detail_list;
private ArrayList<String> contactvalues_list,heading_list;
private MyContactAdapter contactadapter;

private String complete_userinformation; 
protected void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
setContentView(R.layout.information_layout);
 user_detail_list=(ListView) findViewById(R.id.info_list_id);
 cancelinfobtn=(Button) findViewById(R.id.cancelinfobtn_id); 
 shareinfobtn=(Button) findViewById(R.id.sharebtninfo_id);
contactvalues_list=new ArrayList<String>();
heading_list=new ArrayList<String>();
  if(AddressBookResultHandler.person_name!=null)
  {
  heading_list.add("Name");
  contactvalues_list.add(AddressBookResultHandler.person_name[0]);
  }
  if(AddressBookResultHandler.phoneNumbers!=null)
  {
  heading_list.add("Number");
  contactvalues_list.add(AddressBookResultHandler.phoneNumbers[0]);
  }
  if(AddressBookResultHandler.addresses!=null)
  {
  heading_list.add("Address");
  contactvalues_list.add(AddressBookResultHandler.addresses[0]);
  }
  if(AddressBookResultHandler.emails!=null)
  {
  heading_list.add("Email Id");
  contactvalues_list.add(AddressBookResultHandler.emails[0]);
  }
  if(AddressBookResultHandler.person_organization!=null)
  {
  heading_list.add("Company ");
  contactvalues_list.add(AddressBookResultHandler.person_organization);
  }
  if(AddressBookResultHandler.person_website!=null)
  {
  heading_list.add("Website");
  contactvalues_list.add(AddressBookResultHandler.person_website);
  }
  if(AddressBookResultHandler.person_title!=null)
  {
      System.out.println("is i m in title");
  heading_list.add("Title");
  contactvalues_list.add(AddressBookResultHandler.person_title);
  }
  contactadapter=new MyContactAdapter(this,heading_list,contactvalues_list);
  user_detail_list.setDivider(null);
  user_detail_list.setAdapter(contactadapter);
  cancelinfobtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        finish();   
        }
    });
  shareinfobtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
       int requestcode=0;
       complete_userinformation="";

       for(int i=0;i<user_detail_list.getCount();i++)
       {
           try {

           System.out.println("the list count"+user_detail_list.getCount());
           View v1=(View) user_detail_list.getChildAt(0);
           System.out.println("the value of i is:"+i);
           System.out.println("the view is"+v1);
           CheckBox ch=(CheckBox) v1.findViewById(R.id.checkBox1);

           if( ch.isChecked())
           {
            System.out.println("is last one chechbox is checked");
             TextView tv_heading=  (TextView) v1.findViewById(R.id.textView1);
             EditText tv_values= (EditText) v1.findViewById(R.id.textView2); 
          complete_userinformation=complete_userinformation+(String) (tv_heading.getText()+": "+tv_values.getText()+"\n");

       }



           }
           catch(Exception e)
           {
               System.out.println("exception of view is"+e);
           }
       }

现在适配器类

 public class MyContactAdapter extends ArrayAdapter {
 ArrayList<String> userContact_List,userheading_list;
 private Context mcontext;  
 private View rowview;

 public MyContactAdapter(Context context, ArrayList< String> usercontactheading_list,ArrayList<String> usercontactvalue_list ) {
super(context,R.layout.detail_value_layout,usercontactheading_list);
userContact_List=new ArrayList<String>();
userheading_list=new ArrayList<String>();
userContact_List=usercontactvalue_list;
userheading_list=usercontactheading_list;
mcontext=context;
}

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) mcontext
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    rowview = inflater.inflate(R.layout.detail_value_layout, parent, false);
    TextView textView_heading = (TextView) rowview.findViewById(R.id.textView1);
    EditText textview_value= (EditText) rowview.findViewById(R.id.textView2);

    CheckBox checkbox_detail=(CheckBox) rowview.findViewById(R.id.checkBox1);
    textView_heading.setText(userheading_list.get(position));
    textview_value.setText(userContact_List.get(position));
    return rowview;
}   

now xml file 

<TextView
    android:id="@+id/textView1"
    android:layout_width="70dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="18dp"
    android:textSize="16dp"
    android:text="TextView" />


<EditText
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/checkBox1"
    android:layout_toRightOf="@+id/textView1"
     android:layout_marginLeft="5dp"

     android:clickable="false" 
    android:cursorVisible="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false"
    android:inputType="textMultiLine" >

    <requestFocus />
</EditText>

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
   android:layout_marginLeft="5dp"
   android:checked="true"
    android:text="" />

第二个xml

<Button
    android:id="@+id/sharebtninfo_id"
    android:layout_width="160dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Share" />

这是完整的资源,所以请帮助我

4

1 回答 1

1

您可以在文本视图中拥有一个包含所有数据的数组列表...并在单击列表视图项目时...检查复选框的状态..如果它处于未选中状态..从列表中删除该元素...或否则添加元素...然后您的列表中将包含所需的元素...

于 2012-04-24T05:40:36.510 回答