我有一个列表视图,我的列表视图包含3个元素,两个textview和一个复选框,默认情况下我的所有复选框都是true。现在,当我点击列表上的提交按钮,然后我想得到所有检查项目相应的textview信息,但我得到文本视图的信息,在屏幕上可见,但我有很长的列表,所以我必须得到所有textview信息对应他们的复选框检查所以请帮我这样做。帮助者肯定得到一些奖励。
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" />
这是完整的资源,所以PLZ帮助我
答案 0 :(得分:1)
你可以让一个arraylist包含textviews中的所有数据......并在列表视图的项目中单击..检查复选框的状态..如果它处于未选中状态..从列表中删除该元素。 ..或者添加元素...然后你将在列表中包含所需的元素......