Reputation: 1031
i have one list view and my list view contain 3 elements two textview and one check box and my all check box by default is true. Now when i click on submit button on list then i want to get all checked item corresponding textview infromation but i m getting information of text view which are visible in screen but i have long list so i have to get all textview infromation corresponding to their check box is checked so please help me to do this. Helpers are definately getting some reward.
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);
}
}
now adapter class
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="" />
second 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" />
this is complete resource so plz help me
Upvotes: 0
Views: 99
Reputation: 8079
You can have an arraylist with all the data in textviews... and in onclick of the items of list view.. check the status of checkbox.. if it is in unchecked state.. remove that element from your list... or else add the element... then you will have the required elements in your list...
Upvotes: 1