私はLoopJ Android Asynchronous-Http-Clientの新機能です。PHP Webサービスでデータベースからデータを取得する方法を理解しました。spinner androidとAsynchronous-Http-Clientを実装する
マイServiceHandler:
public class ServiceHandler {
private static String BASE_URL="http:/my/url/";
private static String GET_CAT= BASE_URL+"get_cat.php";
private static AsyncHttpClient client= new AsyncHttpClient();
public static void getAllCat(RequestParams params,AsyncHttpResponseHandler asyncHttpResponseHandler
){
client.get(GET_CAT,params,asyncHttpResponseHandler);};}
マイAddBookActivity:このクラスでは、私は、データベースからカテゴリを取得するためにgetAllCatを使用しますが、今どのように私は私のスピナーを読み込むことができますか?
public class AddBookActivity extends AppCompatActivity {
ServiceHandler client = new ServiceHandler();
private Spinner spCat;
@Override
protected void onResume() {
super.onResume();
getAllCat();
}
private void getAllCat(){
client.getAllCat(null, new JsonHttpResponseHandler(){
@Override
public void onSuccess(int statusCode,cz.msebera.android.httpclient.Header[] headers, JSONArray response) {
try {
for (int i=0; i<response.length();i++){
Categories cat = new Categories();
JSONObject obj =response.getJSONObject(i);
cat.setName(obj.getString("name"));
}
}catch (Exception e){
e.printStackTrace();
}}}); }
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_book);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
spCat=(Spinner)findViewById(R.id.spinnercatname);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
にだけで簡単な質問をこのコードを書く - あなたは「カテゴリ名」のリストを含むようにスピナーしたいですか?あなたが探しているものであれば私は解決策を提案できます。 – ishmaelMakitla
まさにあなたが言ったように、スピナーに「カテゴリ名」のリストを含めるようにします。 – Amal
OK、私の答えをチェックして、 。 – ishmaelMakitla