public class MyArrayAdapter extends ArrayAdapter<JsonData> {
// JsonData を格納する、この処理専用の
// ArrayAdapter のカスタマイズ
// コンストラクタで渡された画面の保存
private int mResource;
public MyArrayAdapter(Context context, int resource) {
super(context, resource);
// ArrayAdapter でも、このようにして保存して利用してます
mResource = resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
// 現在の View の取得
// getContext() で super で渡されたものを取得できます
LayoutInflater inflater
= (LayoutInflater) MyArrayAdapter.this.getContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
// super で渡されたものは取得できないので自前で用意します
convertView = inflater.inflate(mResource, null);
}
// アダプターより行データを取得
JsonData json = MyArrayAdapter.this.getItem(position);
// 画面にデータをセット
TextView tv;
// キー
tv = (TextView) convertView.findViewById(R.id.textKey);
tv.setText(json.getCode());
// Subject
tv = (TextView) convertView.findViewById(R.id.textItem1);
tv.setText(json.getName());
// Name
tv = (TextView) convertView.findViewById(R.id.textItem2);
tv.setText(json.getFuri());
// 行の画面をシステムに返す
return convertView;
}
}
JsonData
Android Studio では、private の変数を作っておいて、ALT + Insert から Getter and Setter で一気に作成できます。toString() はここでは特に必要ありませんが、Android の単純リソースを使用するなら必要です。
空のコンストラクタも、新規用のコンストラクタもここでは使用しませんが、前者は Firebase API を使用する際には必要になります。後者も使用しませんが、ALT + Insert で簡単に作成できます。
※ kyuyo が int ではなく long なのも、Firebase API の都合です。
public class JsonData {
private String code;
private String name;
private String furi;
private String birthday;
private String kanri;
private long kyuyo;
private String sex;
private String syozoku;
private String teate;
public JsonData(){}
public JsonData(String birthday, String code, String furi, String kanri, long kyuyo, String name, String sex, String syozoku, String teate) {
this.birthday = birthday;
this.code = code;
this.furi = furi;
this.kanri = kanri;
this.kyuyo = kyuyo;
this.name = name;
this.sex = sex;
this.syozoku = syozoku;
this.teate = teate;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getFuri() {
return furi;
}
public void setFuri(String furi) {
this.furi = furi;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getKanri() {
return kanri;
}
public void setKanri(String kanri) {
this.kanri = kanri;
}
public long getKyuyo() {
return kyuyo;
}
public void setKyuyo(long kyuyo) {
this.kyuyo = kyuyo;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getSyozoku() {
return syozoku;
}
public void setSyozoku(String syozoku) {
this.syozoku = syozoku;
}
public String getTeate() {
return teate;
}
public void setTeate(String teate) {
this.teate = teate;
}
@Override
public String toString() {
return this.name;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
function htmlentities2() {
var a = $("#do_encode").val();
var w = "";
var n = 0;
var p;
for( var i = 0; i < a.length; i++ ) {
p = (a.charCodeAt(i)).toString(16);
if ( p.length > 2 || a.substr( i, 1 ) == "\"" || a.substr( i, 1 ) == "'" ) {
w += "\\u" + ("00"+p).substr(2+p.length-4,4);
}
else {
w += a.substr( i, 1 );
}
}
$("#result").text( w );
}
</script>
<input id="do_encode" type="text" size="60">
<br>
<input
type="button"
value="入力文字列を alert 用16進数表現 に変換"
onclick='htmlentities2()'>
<pre id="result"></pre>