1
tics
에는 3 개의 항목이 있습니다. 다음 코드는 3 개의 티켓 항목을 생성하지만 항상 첫 번째 티켓 TextView
의 텍스트를 설정합니다.getLayoutInflater(). 루프의 inflate()는 항상 첫 번째보기를 반환합니다.
LinearLayout t =(LinearLayout) getLayoutInflater().inflate(R.layout.ticket_row, p);
가 t
가 팽창 View
해야하지 : 다음 코드에서
public void onSuccess(int i, Header[] headers, byte[] bytes) {
progress.dismiss();
String response = new String(bytes);
try{
JSONObject obj = new JSONObject(response);
JSONArray tics = obj.getJSONArray("tickets");
LinearLayout p = (LinearLayout)findViewById(R.id.tickets);
for(int j = 0;j<tics.length();j++){
LinearLayout t =(LinearLayout) getLayoutInflater().inflate(R.layout.ticket_row, p);
TextView topic = (TextView)t.findViewWithTag("topic");
TextView section = (TextView)t.findViewWithTag("section");
TextView datetime = (TextView)t.findViewWithTag("datetime");
JSONObject item = tics.getJSONObject(j);
Toast.makeText(getApplicationContext(),item.getString("Caption") ,Toast.LENGTH_LONG).show();
topic.setText(item.getString("Caption"));
datetime.setText(item.getString("DateString"));
section.setText(item.getString("Section"));
}
}catch (Exception e){}
}
?
보기가 부모에게 추가되지 않습니다. 나는'p.addView (t); '를 사용해야한다. 맞지? –
예, 정확히 ... – Blackbelt
좋아요! 고마워. –