0

我有扩展片段的类

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;
    }

我确定全局变量列表不为空并且包含数据(我用来log.d 显示它的长度),适配器类就像

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(); 

知道如何解决这个问题,我是否错过了片段中的任何内容

4

2 回答 2

4

在 onCreateView 试试这个

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;
于 2016-11-24T13:55:16.030 回答
2

屏幕上没有任何内容是正常的,因为在该onCreateView方法中,您会膨胀布局并设置,ListView但是当需要返回视图(该片段的布局以及ListView放置数据的位置)时,您会执行以下操作:

return inflater.inflate(R.layout.chemounit, container, false);

这将再次用空的布局文件膨胀ListView(因此您之前所做的所有设置都是无用的,因为您丢弃了第一个 inflated View)。相反,您应该返回:

return view;
于 2012-06-12T07:31:20.060 回答