【发布时间】:2016-03-31 18:02:07
【问题描述】:
我正在开发一个 Android 项目,其中有两种不同类型的聊天可能性。一个用于Groups,另一个用于private 或一对一通信。现在,登录用户可以与之聊天的所有组和用户都显示在ConversationActivity 中。
为此,我在 UI 中准备了两个列表,内容将通过 Async 方法添加到每个列表中。每个列表都有一个单独的适配器,我可以使用它轻松识别单击了哪个项目。
这种机制工作得很好,只是当活动打开时,列表看起来它们是相互叠加的,显然这不是本意。所以我在 RelativeLayout 中指出,将它放在另一个之上,这也没有帮助。
如何在一个活动页面中显示两个具有两个不同适配器的列表?
activity_conversations.xml:
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip"
android:layout_above="@+id/privateRelativeLay"
>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/conversationList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip"
android:id="@+id/privateRelativeLay">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/privateConversationList"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
ConversationActivity.java
public class ConversationActivity extends ApplicationDrawerLoader {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_conversations);
if (isOnline()) {
new getConversationsForLoggedInUser(this).execute();
new getPrivateChannelsForLoggedInUser(this).execute();
}
public class getPrivateChannelsForLoggedInUser extends AsyncTask<Void,Void,ResponseEntity<PrivateChannel[]>>{
@Override
protected void onPostExecute(ResponseEntity<PrivateChannel[]> responseEntity) {
privateChannelConversationList = (ListView) findViewById(R.id.privateConversationList);
privateConversationAdapter = new PrivateConversationAdapter(conversationActivity, privateMapList);
privateChannelConversationList.setAdapter(privateConversationAdapter);
// On click adapter excluded
}
public class getConversationsForLoggedInUser extends AsyncTask<Void, Void, ResponseEntity<RestGroupAccount[]>> {
@Override
protected void onPostExecute(ResponseEntity<RestGroupAccount[]> responseEntity) {
super.onPostExecute(responseEntity);
groupAccountConversationList = (ListView) findViewById(R.id.conversationList);
groupConversationAdapter = new GroupConversationAdapter(conversationActivity, groupAccountMapList);
groupAccountConversationList.setAdapter(groupConversationAdapter);
// On click adpater excluded
}
}
我希望这么多信息就足够了,如果需要其他任何信息,请告诉我。你能帮忙的话,我会很高兴。谢谢你。
这是它的外观:截图:
【问题讨论】:
-
如果有人有兴趣查看整个代码,我已将所有代码发布在此粘贴箱中:pastebin.com/huRMFAHa。谢谢.. :-)
-
为什么要使用抽屉布局?为什么你有Relativelayouts 作为其中的包装器?您应该在问题中详细说明这些选择。
-
@wvdz :抽屉布局是显示导航抽屉。与这个问题无关。相对布局,我不知道,我想我在开始这个项目时发现了一些东西,对Android不太了解。谢谢你。 :-)