【问题标题】:Can not dipslay textviews on top of the screen无法在屏幕顶部显示文本视图
【发布时间】:2019-07-19 23:09:18
【问题描述】:

女士们,先生们,您好,

虽然我可以在我的屏幕上接收数据(预订),但是我无法在屏幕上显示一些文本视图。

public class Res extends Fragment {

    ListView lview;
    ListAdapter adapter;
    ProgressDialog loading;

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.reslist, container, false);
        lview = view.findViewById(R.id.lview);

        getReservations();
        return view;

这里如果我膨胀 fragment_reservation 而不是 reslist ,我可以显示 textviews,但我可以显示 listview。

这里是我的列表适配器代码;

adapter = new SimpleAdapter(getActivity(),list,R.layout.fragment_reservations,
                new String[]{"name", "email", "phone", "arriving", "departure", "pax", "roomtype", "rate"}, new int[]{R.id.textView, R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6, R.id.textView7, R.id.textView8});


        lview.setAdapter(adapter);
        loading.dismiss();

可能是关于 getActivty() 的问题,我需要使用不同的方法调用..

提前谢谢...

       here the photo of the screen

SCREEEN

【问题讨论】:

  • 如果需要,我可以发布 xml 文件...我有两个 xml 文件,一个仅用于列表视图,另一个用于文本视图。

标签: android listview android-fragmentactivity


【解决方案1】:

我认为问题在于创建 SimpleAdapter 对象时的参数“list”(ArrayList)。这是我做同样事情的代码,它工作正常。

public class BlankFrag extends Fragment {
private View v;
private ListView listView;
public View onCreateView(LayoutInflater inflater,
                            ViewGroup container,
                            Bundle savedInstanceState){

    v = inflater.inflate(R.layout.blank_fragment, container, false);
    listView = v.findViewById(R.id.dummy_list);

    ArrayList<HashMap<String, String>> list = new ArrayList<>();

    //populating dummy content
    for(int i=0; i<5; i++){
        HashMap<String, String> temp = new HashMap<>();
        temp.put("name", "name"+Integer.toString(i));
        temp.put("sname", "sname"+Integer.toString(i));
        list.add(temp);
    }

    SimpleAdapter adapter = new SimpleAdapter(getActivity(), list, R.layout.single_item, new String[]{"name", "sname"}, new int[]{R.id.name, R.id.sname});

    listView.setAdapter(adapter);

    return v;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多