ИСПРАВЛЕНО! Всех приветствую, у меня есть Json файл находится в директории Assets в нем список всех стран и коды, столицы, и.т.п.. )) выглядеть следующим образом,
[
{
"Name": "Bangladesh",
"Unicode": "🇧🇩",
"Dial": "880"
},
{
"Name": "Belgium",
"Unicode": "🇧🇪",
"Dial": "32"
}
]
теперь вопрос: как мне передавать json file находящийся в директории assets в класс и вызвать его в адаптер?
Мой класс которые не знаю где и как использовать!
import android.os.Parcelable;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class ParseCountry implements Parcelable{
@SerializedName("Name")
@Expose
private String name;
@SerializedName("Unicode")
@Expose
private String unicode;
@SerializedName("Dial")
@Expose
private String dial;
public final static Creator<ParseCountry> CREATOR = new Creator<ParseCountry>() {
@SuppressWarnings({
"unchecked"
})
public ParseCountry createFromParcel(android.os.Parcel in) {
return new ParseCountry(in);
}
public ParseCountry[] newArray(int size) {
return (new ParseCountry[size]);
}
};
protected ParseCountry(android.os.Parcel in) {
this.name = ((String) in.readValue((String.class.getClassLoader())));
this.unicode = ((String) in.readValue((String.class.getClassLoader())));
this.dial = ((String) in.readValue((String.class.getClassLoader())));
}
/**
* No args constructor for use in serialization
*
*/
public ParseCountry() {
}
/**
*
* @param name
* @param unicode
* @param dial
*/
public ParseCountry(String name, String unicode, String dial) {
super();
this.name = name;
this.unicode = unicode;
this.dial = dial;
}
public String getName() {
return name;
}
public String getUnicode() {
return unicode;
}
public String getDial() {
return dial;
}
public void setName(String name) {
this.name = name;
}
public void setUnicode(String unicode) {
this.unicode = unicode;
}
public void setDial(String dial) {
this.dial = dial;
}
public void writeToParcel(android.os.Parcel dest, int flags) {
dest.writeValue(name);
dest.writeValue(unicode);
dest.writeValue(dial);
}
public int describeContents() {
return 0;
}
}
мой адапер
// adapter for select country
adapter = new ArrayAdapter<>(
this,
// if custom ListView R.layout.custom_list_view, R.id.list_view_id
android.R.layout.simple_list_item_1,
getResources().getStringArray(R.array.country_list)); // here for country name !
selectCountry.setAdapter(adapter);