Android ListFragment addfooterview()

时间:2013-12-27 20:11:01

标签: android

我一直在尝试在列表末尾添加页脚按钮。我的列表工作正常然而我无法弄清楚为什么我无法添加页脚视图。
我的最终目标是通过xml来扩充视图并添加页脚按钮但是我需要至少先使用它才能工作。< / p>

public void onActivityCreated(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // storing string resources for users inventory into Array 
    String[] adobe_products = getResources().getStringArray(R.array.adobe_products);

    ListView lv = getListView();
    // Binding Array to ListAdapter        
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.inventory_list, R.id.label, adobe_products);

    // LoadMore button
    Button btnScan = new Button(getActivity());
    btnScan.setText("Scan Inventory");

    // Adding Load More button to list view at bottom
    lv.addFooterView(btnScan); 

    this.setListAdapter(adapter);

    // listening to single list item on click
    lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {

          // selected item 
          String product = ((TextView) view).getText().toString();

          // Launching new Activity on selecting single List Item
          //Intent i = new Intent(PhotosFragment.this, InventoryItem.class);
          // sending data to new activity
          //i.putExtra("product", product);
          //startActivity(i);
      }
    });

    btnScan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // Starting a new async task
            //Intent send_Scan=new Intent(PhotosFragment.this, ScanActivity.class);
            //PhotosFragment.this.startActivity(send_Scan);
        }
    });
}

编辑:     在运行应用程序时,它似乎陷入无限循环。一直加载。

1 个答案:

答案 0 :(得分:1)

您无法在ListView中获得onCreateView

onStart()中使用:

@Override
public void onStart() {
    super.onStart();
    LayoutInflater inflater = getActivity().getLayoutInflater();
    getListView().addFooterView(inflater.inflate(R.layout.ly_footer_acreditacao, null));
}