【问题标题】:list adapter for fragments片段的列表适配器
【发布时间】:2012-03-06 12:45:32
【问题描述】:

我在我的应用程序中使用片段。它用于选项卡功能。在选项卡中,我需要在 viewflipper 中显示一个列表。列表视图是一个单独的 xml 文件。我已经用视图翻转器膨胀了列表视图。内容列表视图的(列表项)是另一个 xml 文件。它包含四个文本视图。文本视图的值是动态设置的。我为此目的创建了一个名为存储适配器的自定义适配器。但问题是我不能使用这个存储适配器在我的程序中。当我使用它时,它不显示值。因为列表视图项目是一个单独的文件,我也无法扩展 listfragment。我不知道我应该怎么做才能显示我的内容。下面是我的代码.请帮帮我。

public class TabStoreLocatorFragment extends Fragment implements OnClickListener {

private Button mapSwitcher;
private LinearLayout lastSelectedStoreButton;
private LinearLayout noSelectedStoreSection;
private TextView storeInfoName;
private TextView storeInfoAddress;
private TextView storeInfoCity;
private RelativeLayout phoneLocationButton;
private EditText searchStoreLocation;
private ListView storeList;
private ViewFlipper storeFlipper;
private LinearLayout theLayout;
private Store store;
private Context context;
private String searchStoreText;

//private ProgressDialog findStoreProgressDialog;
//private StoreItemizedOverlay<StoreOverlayItem> storeOverlay;
//private List<Overlay> mapOverlays;
//private Drawable storePin;

@SuppressWarnings("static-access")
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    if (container == null) {
        // We have different layouts, and in one of them this
        // fragment's containing frame doesn't exist. The fragment
        // may still be created from its saved state, but there is
        // no reason to try to create its view hierarchy because it
        // won't be displayed. Note this is not needed -- we could
        // just run the code below, where we would create and return
        // the view hierarchy; it would just never be used.
        return null;
    }


    context=getActivity().getApplicationContext();
     theLayout = (LinearLayout) inflater.inflate(
            R.layout.tab_store_locator_layout, container, false);

    phoneLocationButton = (RelativeLayout) theLayout.findViewById(R.id.phone_location_button);
    mapSwitcher=(Button)theLayout.findViewById(R.id.switch_state_button);
    lastSelectedStoreButton=(LinearLayout)theLayout.findViewById(R.id.last_selected_store_button);
    noSelectedStoreSection=(LinearLayout)theLayout.findViewById(R.id.no_selected_store);
    storeInfoName=(TextView)theLayout.findViewById(R.id.store_name);
    storeInfoAddress=(TextView)theLayout.findViewById(R.id.store_address);
    storeInfoCity=(TextView)theLayout.findViewById(R.id.store_city);
    searchStoreLocation=(EditText)theLayout.findViewById(R.id.search_store);
    storeFlipper = (ViewFlipper)theLayout.findViewById(R.id.store_flipper);
    storeList = (ListView)inflater.inflate(R.layout.store_list, null);
    storeFlipper.addView(storeList);

    store=new Store(); 
    store.setName("store1");
    store.setAddress("california");
    store.setCity("newyork");
    store.setZipCode("23");
    store.setState("california");

    phoneLocationButton.setOnClickListener(this);
    mapSwitcher.setOnClickListener(this);
    lastSelectedStoreButton.setOnClickListener(this);
    return theLayout;

}


@Override
public void onClick(View view) {
    int id = view.getId();
    if (id == R.id.phone_location_button) {

        searchStoreText=searchStoreLocation.getText().toString();


        @SuppressWarnings("unchecked")
        StoreAdapter adapter = new StoreAdapter(context, R.layout.store_list_item);

        storeList.setAdapter(adapter);



    }
    else if(id == R.id.switch_state_button){

    }
    else{


    }


}

    }

【问题讨论】:

    标签: android listview adapter fragment


    【解决方案1】:

    自定义列表适配器将起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-28
      • 2015-06-11
      • 1970-01-01
      相关资源
      最近更新 更多