0

私は Android の初心者です。Activity で拡張されたクラスがあります。私の質問は、Activity から AsyncTaskLoader を呼び出す方法です。AsyncTaskLoader クラスと、入力された情報が正しい場合にユーザーのステータスを取得する WebService クラスを作成しました。 Activity クラスから AsyncTaskLoader を呼び出すことができません。

public class LoginActivityService extends Activity 
        {  Context context;
        EditText userName,password,version;
        Button loginBtn,logoutBtn;
            @Override
            public void onCreate(Bundle savedInstanceState)
            {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.login_view_service);
            context = this;
            userName = (EditText)findViewById(R.id.userName1);
            password = (EditText)findViewById(R.id.password1);
            loginBtn = (Button)findViewById(R.id.login1);
            logoutBtn = (Button)findViewById(R.id.logout1);
            loginBtn.setOnClickListener(new View.OnClickListener() {

       @Override
        public void onClick(View arg0) {
       // TODO Auto-generated method stub
     if(userName.getText().length() == 0 || password.getText().length() == 0)
  {
          Toast.makeText(context,"UserName Or Password Should be Filled",Toast.LENGTH_SHORT).show();
       }
         else
        {
          userName.setText("");
          password.setText("");
          //getLoaderManager().initLoader(101, null, this);
        }
       }
      });
       }

ローダークラス:

public class LoginLoader extends AsyncTaskLoader<List<User>> 
{
private List<User> listUser;
Context context;
private final String TAG = User.class.getName();
public LoginLoader(Context context)
{super(context);
}
@Override
protected void onStartLoading() {
Log.d(TAG, "starting proposals loader...");
long currentTime = System.currentTimeMillis();
forceLoad();
}
public void loadinBackground()
{
// List<User>  locations=  LoginListService.  // in this line there is a problem Function is not accessible
}
}

LoginListService 関数:

public List<User> getLoginResult()
{
MultiValueMap<String, Object> formData = new LinkedMultiValueMap<String, Object>();
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(formData, WorkflowRestService
            .getInstance().getRequestHeaders());
ResponseEntity<UserListItemHolder> responseEntity = WorkflowRestService.getInstance().getRestTemplate()
            .exchange(WorkflowApp.getServicesURL()+"user/logIn",HttpMethod.POST, requestEntity, UserListItemHolder.class);
  Log.i("response Entity Login",""+responseEntity);
  UserListItemHolder userListItemInstance = responseEntity.getBody();
  Log.i("response Entity Body Location Function",""+responseEntity.getBody());
 if("true".equals(userListItemInstance.getStatus()))
 {
  Log.i("locationInstance.getLocationListItems if",""+userListItemInstance.getUserListItems());
   return userListItemInstance.getUserListItems();
 }
 else
 {
   Log.i("locationInstance.getLocationListItems else",""+userListItemInstance.getUserListItems());
     userListItemInstance = null;
     return userListItemInstance.getUserListItems();
    }

}
4

1 に答える 1

0

Activity はLoaderManager.LoaderCallbacksを実装する必要があると思います。

Android Developers http://developer.android.com/guide/components/loaders.htmlのローダー ガイドをご覧ください。

編集:あなたの問題がonClickリスナーにあることに気づきました。ローダーの初期化呼び出しを次のように変更します。

getLoaderManager().initLoader(101, null, LoginActivityService.this);
于 2014-01-21T09:57:10.837 に答える