Ash*_*ani 1 java android layout-inflater android-studio
将tics有3个项目.以下代码创建3个故障单项,但始终设置TextView第一个故障单的s 的文本.
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){}
}
Run Code Online (Sandbox Code Playgroud)
在以下代码中:
LinearLayout t =(LinearLayout) getLayoutInflater().inflate(R.layout.ticket_row, p);
Run Code Online (Sandbox Code Playgroud)
不t应该膨胀View?
不应该是膨胀的观点吗?
不,您使用的版本将膨胀的视图添加到父级并返回父级本身.你可以用
View inflate (XmlPullParser parser,
ViewGroup root,
boolean attachToRoot)
Run Code Online (Sandbox Code Playgroud)
提供false作为第三个参数.这样android将返回膨胀的视图(父级将仅用于布局parmas).您必须手动将其添加到父级.
| 归档时间: |
|
| 查看次数: |
492 次 |
| 最近记录: |