简体   繁体   中英

How to get the json array data and display in SPINNERS android

How i can get the json data and display in spinners can u help me please i want to display state name and code in spinners Here is my Activity

below is the postman image in which i am getting state name and state code so now how i can get and display in spinners please help me

String country_id = "in";

    Call<ResponseBody> call = SignupClient
            .getInstance()
            .getApi()
            .users(country_id);

    call.enqueue(new Callback<ResponseBody>() {
        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {



        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Toast.makeText(SignupActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });

Here is my Java Class

public class SignupClient {

private static final String BASE_URL = "http://74.207.233.160/";
private static SignupClient mInstance;
private Retrofit retrofit;

private SignupClient() {
    retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

public static synchronized SignupClient getInstance() {
    if (mInstance == null)
    {
        mInstance = new SignupClient();
    }
    return mInstance;
}

public SignupApi getApi() {
    return retrofit.create(SignupApi.class);
}
}

Here is my Api

public interface SignupApi {

@FormUrlEncoded
@POST("find_states")
Call<ResponseBody> users(
        @Field("country_id") String country_id
);
}

Here is my postman image 邮差

Try this: (replace "FilterTable" with your Pojo class name)

class CustomArrayAdapterForSpinner(private val filterValues: List<FilterTable>) : BaseAdapter() {
private val inflater: LayoutInflater
var name: String? = null

val count: Int
    @Override
    get() = filterValues.size()

init {
    inflater = getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
}

@Override
fun getItem(position: Int): Object {
    return filterValues[position]
}

@Override
fun getItemId(position: Int): Long {
    return position.toLong()
}

@Override
fun getView(position: Int, view: View, parent: ViewGroup): View {
    val holder: Holder
    var convertView = view
    if (convertView !=null) {
        holder = convertView.getTag()
    } else {
        holder = Holder()
        convertView = inflater.inflate(R.layout.row_filter, null)
        holder.chkTextView = convertView.findViewById(R.id.checkTxt)
        convertView.setTag(holder)
    }
    holder.chkTextView!!.setText(filterValues[position].getName())
    holder.chkTextView!!.setTag(if (filterValues[position].isSelection()) "unChecked" else "checked")
    return convertView
}

fun setSelection(str: String) {
    for (model in filterValues)
        model.setSelection(model.getName().equals(str))
}

internal inner class Holder {
    var chkTextView: CheckedTextView? = null
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM