Android開発は初めてです。
XML に比べて JSON キャリアの軽さを考慮して、単純なアプリケーションで JSON オブジェクトと配列を使用することを純粋に好みます。
ListView を設定するために ArrayAdapter に課題がありました。
これが私が克服する方法であり、それに関するあなたの提案が必要です。
Extend the Adaptor class.
次に、JSONArray をコンストラクターに渡します。
ここで、コンストラクターは、JSONArray の長さを設定するダミーの String 配列を使用して super を呼び出します。
コンストラクターの引数をクラスに格納して、後で使用できるようにします。
public myAdaptor(Context context, int resource, JSONArray array)
{
super(context, resource, new String[array.length()]);
// Store in the local varialbles to the adapter class.
this.context = context;
this.resource = resource;
this.profiles = objects;
}
getView ()は、JSONArray から JSONObjects を取得してビューを構築するジョブを実行します。
public View getView(int position, View convertView, ViewGroup parent)
{
View view;
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(resource, parent, false);
}
else
{
view = convertView;
}
// Here
JSONObject item = (JSONObject) profiles.getJSONObject(position);
// READY WITH JSONObject from the JSONArray
// YOUR CODE TO BUILD VIEW OR ACCESS THE
}
現在、改善/提案/思慮深い質問はありますか??