-2
我建立一個應用程序,得3個接觸從聯繫人拿到手機號,, 我希望有一個現成的代碼來做到這一點,也顯示給用戶的佈局等,其中他選擇的數字。我聽說,這個任務是在後臺線程我在想,如果我會做到這一點使用代碼從通訊錄中的Android
extending AsynTask
是真的做?請給我完整的代碼來做到這一點。
我的活動中,我必須包括該代碼是這樣的:
public class Registration extends Activity implements View.OnClickListener {
RegisteredUser user;
EditText name,mobile ;
Button guardian1,guardian2;
@Override
protected void onCreate(Bundle savedInstanceState) {
Button submit;
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
submit = (Button) findViewById(R.id.register_registration_submit);
submit.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.register_registration_submit:
if(isConnected()){
if(inputData())
Log.d("gone","hum");
new SendRegistrationData(getBaseContext(),Registration.this).execute(user);
}
else
Toast.makeText(getBaseContext(), "You are not connected to internet.Please connect yourself and try again.", Toast.LENGTH_LONG).show();
break;
default: Log.d("application","no button match");
}
}
private boolean inputData() {
user = new RegisteredUser();
name = (EditText) findViewById(R.id.registration_name);
mobile = (EditText) findViewById(R.id.registration_mob);
user.setName(name.getText().toString().trim());
user.setMobile(mobile.getText().toString().trim());
//code to input name and mobile and also validation
//** HERE I WANT CODE TO GET 3 CONTACTS .WHEN USER CLICK ON BUTTON.
button.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
new GetContact().execute();
}
});
/*/ also put a validation to check either the user has choosen
all three contacts if not,, return false to input data ,,
so that form can not be submitted */
return true;
}
public boolean isConnected(){
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
return true;
else
return false;
}
}
感謝..但它是我的項目的一個非常小的一部分,,所以我希望一個現成的代碼,,, – sagar