我有扩展片段的类
public class oUnit extends Fragment {
我想填充列表并将其添加到线性布局,因此我使用以下代码
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ProgressDialog connectionProgressDialog = new
ProgressDialog( getActivity());
connectionProgressDialog.setCancelable(false);
connectionProgressDialog.setCanceledOnTouchOutside(false);
connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
connectionProgressDialog.setMessage("Uploading Leads...");
connectionProgressDialog.show();
View view = inflater.inflate(
R.layout.chemounit,
container,
false);
//Intialize the record Grid
LinearLayout formLayout = (LinearLayout)view.findViewById(R.id.UnitGrid);
formLayout.removeAllViews();
MainGrid = new ListView(getActivity().getApplicationContext());
MainGrid.setVisibility(ListView.VISIBLE);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
MainGrid.setLayoutParams(params);
//2. Call the web Service
GlobalVariables appState = (GlobalVariables) getActivity().getApplication();
Log.d(" in Chemo unit"," the array is has "+ appState.encounters.size());
MainGrid.setAdapter(new Encounteradapter(view.getContext(),R.id.ChemoUnitGrid , appState.encounters));
// Finally add it
formLayout.addView(MainGrid);
connectionProgressDialog.dismiss();
return view;
}
我确信全局变量列表不是null并且包含数据(我使用log.d
来显示它的长度),Adapter类就像
public class Encounteradapter extends ArrayAdapter<Encounter> {
private final Context context;
TextView textViewTime ;
TextView textViewPatientName;
Button ButottonArrive ;
Button ButottonEncounter;
Button ButottonExit;
ArrayList<Encounter> Encounters ;
public Encounteradapter(Context context, int ResourceId,
ArrayList<Encounter> items)
{
super(context, ResourceId, items);
this.context = context;
this.Encounters = items ;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.chemounitgrid, parent, false);
Encounter EncounterObject = Encounters.get(position);
textViewTime = (TextView) rowView.findViewById(R.id.Time);
textViewTime.setText(EncounterObject.bookingDate);
textViewPatientName = (TextView) rowView.findViewById(R.id.Time);
textViewPatientName.setText(EncounterObject.Name);
ButottonArrive = (Button) rowView.findViewById(R.id.test1);
ButottonEncounter = (Button) rowView.findViewById(R.id.test2);
ButottonExit = (Button) rowView.findViewById(R.id.test3);
rowView.setTag(position);
return rowView;
}
}
但没有出现列表没有出现,我也尝试重新设置我设置的属性部分,但没有任何一个
这是我尝试在片段OnCreate()上显示进度的第一个问题,但它没有出现我使用以下代码
connectionProgressDialog = new ProgressDialog(getActivity());
connectionProgressDialog.setCancelable(false);
connectionProgressDialog.setCanceledOnTouchOutside(false);
connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
connectionProgressDialog.setMessage("Uploading Leads...");
connectionProgressDialog.show();
任何想法如何解决这个问题,我是否会错过片段
中的任何内容答案 0 :(得分:4)
View view=inflater.inflate(R.layout.chemounit, container, false);
ProgressDialog connectionProgressDialog = new ProgressDialog(getActivity());
connectionProgressDialog.setCancelable(false);
connectionProgressDialog.setCanceledOnTouchOutside(false);
connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
connectionProgressDialog.setMessage("Uploading Leads...");
connectionProgressDialog.show();
return view;
答案 1 :(得分:2)
您在屏幕上没有任何内容是正常的,因为在onCreateView
方法中,您需要对布局进行充气并设置ListView
,但是当它返回视图时(布局)您执行的ListView
放置数据的片段:
return inflater.inflate(R.layout.chemounit, container, false);
会再次使用空ListView
对布局文件进行充气(因此,您丢弃第一个充气的View
时,之前完成的所有设置都无用)。相反,你应该返回:
return view;