在一个framelayout中,通过LayoutInflater.from(context).inflate()方法得到的一个view,里面的listview为什么没有显示?
代码如下
public class AlarmLayout extends FrameLayout {
Context context;
public AlarmLayout(Context context) {
super(context);
this.context = context;
init();
}
public AlarmLayout(Context context, AttributeSet attrs) {...}
public AlarmLayout(Context context, AttributeSet attrs, int defStyleAttr) {...}
private void init() {
View view = LayoutInflater.from(context).inflate(R.layout.activity_alarm, null);
TextView tv = (TextView) view.findViewById(R.id.alarm_id);
tv.setText("ssss");
ListView alarmList = (ListView) view.findViewById(R.id.alarm_list2);
ArrayAdapter<AlarmData> arrayAdapter;
arrayAdapter = new ArrayAdapter<AlarmData>(view.getContext(), android.R.layout.simple_list_item_1);
arrayAdapter.add(new AlarmData(Calendar.getInstance()));
alarmList.setAdapter(arrayAdapter);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(-1, -1);
this.addView(view, lp);
}
}
AlarmData是自定义的一个类,已经复写toString方法,textView可以正常显示。