로 선택하고 내가 여러 연락처를 선택하고 다음 활동에서의 전자 메일 주소를 복사 할 수 있습니다안드로이드 스튜디오 SQL 데이터베이스 표시 및 여러 내가 목록보기에서 mg의 SQL 데이터베이스에 연락처를 표시 할 것이
여기 내 SQL 데이터베이스에 연락처를 표시하는 코드입니다하지만 난을 선택 여러 날 수 있도록 실 거예요 ..
public class MainActivity extends ActionBarActivity {
private ListView contact_list=null;
private EditText search=null;
private List contacts=null;
private Contact contact=null;
private Service service=null;
public static final int OPTION_DIALOG = 1;
private PopupWindow popupWindow;
private ListView menuListView;
EditText editTextEmail, editTextSubject, editTextMessage;
Button btnSend, btnAttachment;
String email, subject, message, attachmentFile;
Uri URI = null;
private static final int PICK_FROM_GALLERY = 101;
int columnIndex;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.contact_list = (ListView) findViewById(R.id.contact_list);
DatabaseAccess databaseAccess = DatabaseAccess.getInstance(this);
databaseAccess.open();
List<String> contact = databaseAccess.getQuotes();
databaseAccess.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_gallery_item, contact);
this.contact_list.setAdapter(adapter);
service = new Service(this);
init();
getContent();
initPopupWindow();
}
private void init(){
contact_list = (ListView)findViewById(R.id.contact_list);
contact_list.setCacheColorHint(Color.TRANSPARENT);
contact_list.setOnItemClickListener(new ViewItemListener());
search = (EditText)findViewById(R.id.search);
search.addTextChangedListener(new SearchTextChangedListener());
}
private void getContent() {
List mylist = new ArrayList();
String queryName = search.getText().toString();
contacts = service.getByName(queryName); // get an contacts array
if (contacts != null) {
for (int i = 0; i < contacts.size(); i++) {
Contact contact = (Contact) contacts.get(i);
// HashMap
HashMap map = new HashMap();
if (contact.getDepartment().equals("IT"))
{
map.put("tv_image", R.drawable.icon_mis);
} if (contact.getDepartment().equals("HRD")){
map.put("tv_image", R.drawable.icon_hrd);
} if (contact.getDepartment().equals("Pubs")){
map.put("tv_image", R.drawable.icon_pubs);
} if (contact.getDepartment().equals("Finance")){
map.put("tv_image", R.drawable.icon_finance);
} if (contact.getDepartment().equals("Sales")){
map.put("tv_image", R.drawable.icon_sales);
} if (contact.getDepartment().equals("CRC")){
map.put("tv_image", R.drawable.icon_crc);
} if (contact.getDepartment().equals("OED")){
map.put("tv_image", R.drawable.icon_oed);
} if (contact.getDepartment().equals("OP")){
map.put("tv_image", R.drawable.icon_op);
} if (contact.getDepartment().equals("EMD")){
map.put("tv_image", R.drawable.icon_emd);
} if (contact.getDepartment().equals("TD")){
map.put("tv_image", R.drawable.icon_td);
//}else {
// map.put("tv_image", R.drawable.icon_spred);
}
map.put("tv_name", contact.getName());
map.put("tv_phone", contact.getPhone());
mylist.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(this, mylist,
R.layout.my_list_item,
new String[]{"tv_image", "tv_name", "tv_phone"},
new int[]{R.id.user_image, R.id.item_name,
R.id.item_phone});
contact_list.setAdapter(adapter);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.add_contact) {
Intent intent = new Intent(MainActivity.this, AddActivity.class);
startActivity(intent);
return true;
}
if(id == R.id.more) {
if(popupWindow.isShowing())
popupWindow.dismiss();
else
popUp();
return true;
}
if(id == R.id.emailaddress) {
if(popupWindow.isShowing())
popupWindow.dismiss();
else
popUp();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onRestart() {
getContent();
super.onRestart();
}
protected Dialog onCreateDialog(int id){
Dialog dialog;
switch(id){
case OPTION_DIALOG:
dialog = createOptionDialog();
break;
default:
dialog = null;
}
return dialog;
}
private Dialog createOptionDialog(){
final Dialog optionDialog;
View optionDialogView = null;
LayoutInflater li = LayoutInflater.from(this);
optionDialogView = li.inflate(R.layout.option_dialog, null);
optionDialog = new AlertDialog.Builder(this).setView(optionDialogView).create();
ImageButton ibCall =
(ImageButton)optionDialogView.findViewById(R.id.dialog_call);
ImageButton ibView = `enter code
here`(ImageButton)optionDialogView.findViewById(R.id.dialog_view);
ImageButton ibSms =
(ImageButton)optionDialogView.findViewById(R.id.dialog_sms);
ImageButton ibEmailadd = (ImageButton)
optionDialogView.findViewById((R.id.dialog_emailadd));
ibCall.setOnClickListener(new ImageButtonListener());
ibSms.setOnClickListener(new ImageButtonListener());
ibEmailadd.setOnClickListener(new ImageButtonListener());
return optionDialog;
}
private void initPopupWindow(){
View view = getLayoutInflater().inflate(R.layout.popup_window, null);
menuListView = (ListView)view.findViewById(R.id.popup_list_view);
popupWindow = new PopupWindow(view, 260, WindowManager.LayoutParams.WRA`enter code here`P_CONTENT);
List<Map<String, Object>> data = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("menu_about", "About CFA");
data.add(map);
SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.popup_list_item,
new String[]{"menu_about"}, new int[]{R.id.menu_about});
menuListView.setAdapter(adapter);
menuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
Intent intent = new Intent(MainActivity.this,AboutActivity.class);
startActivity(intent);
popupWindow.dismiss();
break;
}
}
});
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
}
private void popUp(){
popupWindow.showAsDropDown(this.findViewById(R.id.more), 0, 2);
}
//**************** internal class as Listener ******************
class SearchTextChangedListener implements TextWatcher{
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
getContent();
}
}
class ViewItemListener implements OnItemClickListener{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// get the contact from the contacts array.
contact = (Contact)contacts.get(position);
showDialog(OPTION_DIALOG);
}
}
class ImageButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.dialog_call:
if (contact.getPhone().equals("")) {
Toast.makeText(MainActivity.this, "No Phone No.", Toast.LENGTH_LONG).show();
} else {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + contact.getPhone()));
intent.addCategory("android.intent.category.DEFAULT");
startActivity(intent);
}
dismissDialog(OPTION_DIALOG);
break;
case R.id.dialog_view:
// Send an intent, Active the detailActivity
Intent intent = new Intent(MainActivity.this, DetailActivity.class);
intent.putExtra("id", contact.getId());
startActivity(intent);
dismissDialog(OPTION_DIALOG);
break;
case R.id.dialog_emailadd:
if (contact.getEmail().equals("")) {
Toast.makeText(MainActivity.this, "No Email Add.", Toast.LENGTH_LONG).show();
} else{
Intent intent3 = new Intent(MainActivity.this, EmailActivity.class);
intent3.putExtra("id", contact.getId());
startActivity(intent3);
}
dismissDialog(OPTION_DIALOG);
break;
case R.id.dialog_sms:
if (contact.getPhone().equals("")) {
Toast.makeText(MainActivity.this, "No Phone no.", Toast.LENGTH_LONG).show();
} else {
Intent intent1 = new Intent();
intent1.setAction(Intent.ACTION_SENDTO);
intent1.setData(Uri.parse("smsto:" + contact.getPhone()));
intent1.addCategory("android.intent.category.DEFAULT");
startActivity(intent1);
}
dismissDialog(OPTION_DIALOG);
break;
}
}
}
}
보기에 체크 박스를 추가하고 ** go * 버튼/이벤트에 체크 표시를하면 체크 된 모든 것을 처리 할 수 있습니까? – MikeT
어떻게 할 수 있습니까? 레이아웃에서 말이야? – sweetcha143
당신은 simpleadadapter를 사용하고 있습니다. 그러나 배열에 boolean을 추가하면 간단한 어댑터가 확인란을 추가 할 수 있다고 생각합니다. 개인적으로 나는 항상 xml 레이아웃을 통해 뷰를 정의하는 cutsom 어댑터를 사용합니다. – MikeT