Android 为片段列出适配器

Android 为片段列出适配器,android,listview,adapter,fragment,Android,Listview,Adapter,Fragment,我正在我的应用程序中使用片段。它用于选项卡功能。在选项卡中,我需要在viewflipper中显示列表。列表视图是一个单独的xml文件。我已使用view flipper对列表视图进行充气。内容(列表项)列表视图的另一个xml文件。它包含四个文本视图。文本视图的值正在动态设置。为此,我创建了一个名为store adapter的自定义适配器。但问题是我无法在程序中使用此存储适配器。当我使用此文件时,它不会显示值。因为列表视图项是一个单独的文件我也无法扩展listfragment。我不知道该如何显示我的

我正在我的应用程序中使用片段。它用于选项卡功能。在选项卡中,我需要在viewflipper中显示列表。列表视图是一个单独的xml文件。我已使用view flipper对列表视图进行充气。内容(列表项)列表视图的另一个xml文件。它包含四个文本视图。文本视图的值正在动态设置。为此,我创建了一个名为store adapter的自定义适配器。但问题是我无法在程序中使用此存储适配器。当我使用此文件时,它不会显示值。因为列表视图项是一个单独的文件我也无法扩展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{


    }


}

    }
公共类TabStoreLocatorFragment扩展了片段实现OnClickListener{
专用按钮地图切换器;
private Linear Layout Last Selected Store按钮;
私人线路布局非选定门店部分;
私有TextView storeInfoName;
私有文本视图存储信息地址;
私人TextView storeInfoCity;
私人相对电话定位按钮;
私人编辑文本搜索存储位置;
私有ListView存储列表;
私有视图翻转器商店翻转器;
私人线路布置图;
私人店铺;
私人语境;
私有字符串搜索存储文本;
//private ProgressDialog findStoreProgressDialog;
//私有StoreItemizedOverlay storeOverlay;
//私有列表覆盖图;
//私人可抽出式储物柜;
@抑制警告(“静态访问”)
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
if(容器==null){
//我们有不同的布局,在其中一个
//片段的包含帧不存在。该片段
//仍然可以从其已保存状态创建,但是
//没有理由尝试创建其视图层次结构,因为
//不会显示。请注意,这不是必需的--我们可以
//只需运行下面的代码,我们将在其中创建并返回
//视图层次结构;它永远不会被使用。
返回null;
}
context=getActivity().getApplicationContext();
布局=(线性布局)充气器。充气(
R.layout.tab_商店_定位器_布局,容器,错误);
phoneLocationButton=(RelativeLayout)theLayout.findViewById(R.id.phone\u location\u按钮);
mapSwitcher=(按钮)Layout.findViewById(R.id.switch\u state\u按钮);
lastSelectedStoreButton=(LinearLayout)Layout.findViewById(R.id.last_selected_store_button);
noSelectedStoreSection=(LinearLayout)layout.findViewById(R.id.no\u selected\u store);
storeInfoName=(TextView)theLayout.findViewById(R.id.store\u name);
storeInfoAddress=(TextView)theLayout.findViewById(R.id.store\u地址);
storeInfoCity=(TextView)theLayout.findviewbyd(R.id.store\u city);
searchStoreLocation=(EditText)theLayout.findViewById(R.id.search\u store);
storeFlipper=(ViewFlipper)布局。findViewById(R.id.store\u flipper);
storeList=(ListView)充气器。充气(R.layout.store\u list,null);
storeFlipper.addView(storeList);
store=新商店();
store.setName(“store1”);
store.setAddress(“加利福尼亚”);
store.setCity(“纽约”);
store.setZipCode(“23”);
store.setState(“加利福尼亚州”);
setOnClickListener(这个);
setOnClickListener(此);
lastSelectedStoreButton.setOnClickListener(此);
返回布局;
}
@凌驾
公共void onClick(视图){
int id=view.getId();
if(id==R.id.phone\u位置\u按钮){
searchStoreText=searchStoreLocation.getText().toString();
@抑制警告(“未选中”)
StoreAdapter=新的StoreAdapter(上下文,R.layout.store\u列表\u项);
setAdapter(适配器);
}
else if(id==R.id.switch\u state\u按钮){
}
否则{
}
}
}

自定义列表适配器可以工作