Auswahl i wählen haben alle Kontrollkästchen Kontakt, durch diese Auswahl i alle unten genannten Kontaktinformationen in Telefonliste ausgewählt bekommen wollen, wie kann ich das tun?/wie alle Kontrollkästchen durch eine
kann jemand bitte helfen
ich habe für Einzelkontakt Code unten arbeiten wählen ich möchte alle gefällt die Aussicht auf App unter
Code für einzelne ausgewählte einzelne Kontrollkästchen Arbeits
01 sehen wählenHauptcode
public class TabFragment1 extends Fragment implements CallBack {
Context context = null;
ContactsAdapter objAdapter;
private ArrayList<ContactObject> contactList = new ArrayList<ContactObject>();
private ListView listView;
private ContactsAdapter adapter;
private Button doneBtn , sendBtn;
ProgressDialog pDialog;
TextView buttonAdd;
LinearLayout container;
HorizontalScrollView mHorizontalScrollView;
EditText textIn;
ContactObject mContactObject;
CallBack mCallBack;
ToggleButton toggleButton;
CheckBox select_all;
private ArrayAdapter arrayAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// return super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.activity_main, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
context = getActivity();
mCallBack = this;
pDialog = new ProgressDialog(context);
pDialog.setMessage("Loading...");
pDialog.show();
listView =(ListView) view.findViewById(R.id.list);
// totalSmsCount = (TextView) view.findViewById(R.id.TotalMsgSent);
sendBtn = (Button) view.findViewById(R.id.submitBtn);
// totalSmsCount.setText("Total message sent 100/1000");
mHorizontalScrollView = (HorizontalScrollView)view.findViewById(R.id.container);
container = (LinearLayout)view.findViewById(R.id.linearcontainer);
textIn = (EditText)view.findViewById(R.id.textin);
buttonAdd = (Button)view.findViewById(R.id.add);
select_all = (CheckBox) view.findViewById(R.id.chkall);
// toggleButton=(ToggleButton)view.findViewById(R.id.toggleButton);
addContactsInList();
buttonAdd.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View arg0) {
String msg1 = textIn.getText().toString().trim();
if (!msg1.equals("") && msg1.length() == 10) {
LayoutInflater layoutInflater =
(LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.add_contact, null);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
textOut.setText(textIn.getText().toString().trim());
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addView.getParent()).removeView(addView);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
for (ContactObject bean : ContactsListClass.manualList) {
Log.e("remove","bean.getNumber()="+bean.getNumber());
Log.e("remove","TextView.getNumber()="+textOut.getText().toString());
String str1= bean.getNumber();
String str2= textOut.getText().toString();
if(str1.equals(str2))
{
Log.e("remove","Before="+ContactsListClass.manualList.size());
Log.e("remove", bean.getNumber());
ContactsListClass.manualList.remove(bean);
Log.e("remove", "After=" + ContactsListClass.manualList.size());
break;
}
}
}
});
container.addView(addView);
mContactObject = new ContactObject();
mContactObject.setNumber(textIn.getText().toString().trim());
mContactObject.setName("");
ContactsListClass.manualList.add(mContactObject);
textIn.setText("");
mHorizontalScrollView.postDelayed(new Runnable() {
public void run() {
mHorizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 100L);
} else {
new AlertDialog.Builder(context)
.setTitle("Alert")
.setMessage("Enter valid number.")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
}});
sendBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.i("Selected contact","size="+ ContactsListClass.phoneList.size());
StringBuffer sb = new StringBuffer();
for (ContactObject bean : ContactsListClass.phoneList) {
if (bean.isSelected()) {
sb.append(bean.getName());
sb.append(",");
Log.i("Selected contact", sb.toString());
contactList.add(bean);
}
}
for (ContactObject bean : ContactsListClass.manualList) {
contactList.add(bean);
}
if(contactList.size() > 0 ) {
container.removeAllViews();
Intent i = new Intent(context, WriteMessage.class);
// i.putExtra("Contact_list", contactList);
context.startActivity(i);
}else{
new AlertDialog.Builder(context)
.setTitle("No Contact")
.setMessage("Please select atleast one contact.")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
}
});
}
@Override
public void onResume() {
super.onResume();
contactList.clear();
if(objAdapter!= null) {
objAdapter.notifyDataSetChanged();
}
for (ContactObject bean : ContactsListClass.manualList) {
LayoutInflater layoutInflater =
(LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.add_contact, null);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
textOut.setText(bean.getNumber());
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addView.getParent()).removeView(addView);
TextView textOut = (TextView) addView.findViewById(R.id.textout);
for (ContactObject bean : ContactsListClass.manualList) {
Log.e("remove", "bean.getNumber()=" + bean.getNumber());
Log.e("remove", "TextView.getNumber()=" + textOut.getText().toString());
String str1 = bean.getNumber();
String str2 = textOut.getText().toString();
if (str1.equals(str2)) {
Log.e("remove", "Before=" + ContactsListClass.manualList.size());
Log.e("remove", bean.getNumber());
ContactsListClass.manualList.remove(bean);
Log.e("remove", "After=" + ContactsListClass.manualList.size());
break;
}
}
}
});
container.addView(addView);
}
mHorizontalScrollView.postDelayed(new Runnable() {
public void run() {
mHorizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 100L);
}
private void getSelectedContacts() {
// TODO Auto-generated method stub
StringBuffer sb = new StringBuffer();
for (ContactObject bean : ContactsListClass.phoneList) {
if (bean.isSelected()) {
sb.append(bean.getName());
sb.append(",");
}
}
String s = sb.toString().trim();
if (TextUtils.isEmpty(s)) {
Toast.makeText(context, "Select atleast one Contact",
Toast.LENGTH_SHORT).show();
} else {
s = s.substring(0, s.length() - 1);
Toast.makeText(context, "Selected Contacts : " + s,
Toast.LENGTH_SHORT).show();
}
}
private void addContactsInList() {
// TODO Auto-generated method stub
Thread thread = new Thread() {
@Override
public void run() {
showPB();
try {
// ActivityCompat.requestPermissions(getActivity(),new String[]{Manifest.permission.READ_CONTACTS},1);
Cursor phones = getActivity().getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, null, null, null);
try {
ContactsListClass.phoneList.clear();
} catch (Exception e) {
}
while (phones.moveToNext()) {
String phoneName = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
String phoneImage = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.PHOTO_URI));
ContactObject cp = new ContactObject();
cp.setName(phoneName);
cp.setNumber(phoneNumber);
cp.setImage(phoneImage);
ContactsListClass.phoneList.add(cp);
}
phones.close();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// llContainer.addView(lv);
objAdapter = new ContactsAdapter(getActivity(),
ContactsListClass.phoneList,mCallBack);
listView.setAdapter(objAdapter);
objAdapter.notifyDataSetChanged();
pDialog.hide();
}
});
Collections.sort(ContactsListClass.phoneList,
new Comparator<ContactObject>() {
@Override
public int compare(ContactObject lhs,
ContactObject rhs) {
return lhs.getName().compareTo(
rhs.getName());
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
CheckBox chk = (CheckBox) view
.findViewById(R.id.contactcheck);
ContactObject bean = ContactsListClass.phoneList
.get(position);
if (bean.isSelected()) {
bean.setSelected(false);
chk.setChecked(false);
} else {
bean.setSelected(true);
chk.setChecked(true);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
hidePB();
}
};
thread.start();
}
void showPB() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
});
}
void hidePB() {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
});
}
public void onEventCheck(ContactObject mContactObject)
{
setContact(mContactObject);
}
void setContact(ContactObject mContactObject)
{
Log.e("remove","inside setContact");
LayoutInflater layoutInflater =
(LayoutInflater)getActivity().getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.add_contact, null);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
textOut.setText(mContactObject.getNumber());
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((LinearLayout) addView.getParent()).removeView(addView);
TextView textOut = (TextView)addView.findViewById(R.id.textout);
for (ContactObject bean : ContactsListClass.manualList) {
Log.e("remove","bean.getNumber()="+bean.getNumber());
Log.e("remove","TextView.getNumber()="+textOut.getText().toString());
String str1= bean.getNumber();
String str2= textOut.getText().toString();
if(str1.equals(str2))
{
Log.e("remove","Before="+ContactsListClass.manualList.size());
Log.e("remove", bean.getNumber());
ContactsListClass.manualList.remove(bean);
Log.e("remove", "After=" + ContactsListClass.manualList.size());
break;
}
}
}
});
container.addView(addView);
mHorizontalScrollView.postDelayed(new Runnable() {
public void run() {
mHorizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 100L);
}
}
http://stackoverflow.com/questions/24690605/selecting-all-items-in-a-listview-on-checkbox-select –