我被卡住了,我没有得到如何实现一个ListView里面的片段,我试图做一个聊天gui。包含自定义ListView的片段
是否有可能做这样的事情或我总是在风中?
感谢您的帮助!问候新手! ^^
这里是片段代码:
public static class ChatFragment extends Fragment {
public ChatFragment() {
// Empty constructor required for fragment subclasses
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_chat, container, false);
/*FragmentManager fm = getActivity().getFragmentManager();
DataListFragment list = new DataListFragment();
fm.beginTransaction().add(R.id.list_message_History, list).commit();
*/
getActivity().setTitle(R.string.chat);
return rootView;
}
}
但正如你看到我不udnerstand如何连接这一切。我有一个自定义的ListFragment,它使用ArrayAdapter来处理数据。
这是我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@id/android:list"
android:orientation="horizontal">
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />
</LinearLayout>
</LinearLayout>
你必须为此制作自定义适配器 – Piyush
你是什么意思? – westberg
我有一个ListFragment类,它扩展了ListFragment,并且该类正在使用自定义的ArrayAdapter类。但是,我如何将它们连接到片段? – westberg