كيفية تضخيم تخطيط ديناميكيا؟
-
07-09-2020 - |
سؤال
لدي التصميم التالي المحدد في XML:
giveacodicetagpre.كيف يمكنني استخدام Layoutinflater للاستيلاء على ListView و ProgressBar وتعيينه في التعليمات البرمجية؟
المحلول
بهذه الطريقة:
giveacodicetagpre.نصائح أخرى
You just need the activity reference and call :
RelativeLayout relativeLayout = (RelativeLayout)activity.getLayoutInflater().inflate(R.layout.your_layout, null);
Then you can grab the two view using their ids
relativeLayout.findViewById(R.id.anId);
try this
RelativeLayout myLayout = (RelativeLayout)getLayoutInflater().inflate(
R.layout.you_xml_id, null);
ListView list = (ListView)myLayout.findViewById(R.id.streamListView);
ProgressBar bar = (ProgressBar)myLayout.findViewById(R.id.streamProgressBar);
private LayoutInflater mInflater;
View convertView;
mInflater = LayoutInflater.from(context);
convertView = mInflater.inflate(R.xml.yourxmlname, null);
now you can access the items by
convertView.findViewById
or if you hav lots of Instances, you may define a viewholder
static class CalViewHolder {
ListView con_list;
Progressbar con_progress;
}
holder = new CalViewHolder();
convertView.setTag(holder);
لا تنتمي إلى StackOverflow