Pra*_*ela 9 navigation android listview slider navigation-drawer
我试图在导航抽屉中获得以下功能,但我无法打破它.
场景: -
我有一个导航抽屉.单击导航抽屉中的任何项目时,我需要一个列表视图,其中包含多个项目,可以进一步选择某种功能.我还附上了Image,它将以适当的方式定义我的需求.请有一个图像的参考,以获得我基本上和实际需要的东西.
任何帮助,将不胜感激..!
当我看到你的图像时,我的理解是,从你的抽屉中单击你希望另一个列表出现在它的右侧。我对么 ? 如果我更正,则无法使用 ExpandableListView,因为ExpandableListView 将在单击的项目下方生成项目。
所以一种解决方案是你可以使用两个ListView。
第一个 ListView 位于抽屉内,第二个位于主要内容上,并为两个 ListView 创建自定义适配器。
现在,当用户单击抽屉列表项时,确定单击的是哪个选项,例如城市、我的新闻或其他选项。
识别单击后,您可以根据用户单击的选项填充第二个 ListView 的适配器。并将该适配器应用于第二个 ListView 并通知它。
因此,当用户单击抽屉中的另一个项目时,也会发生同样的事情。但是第二个 ListView 的数据将会改变。
我希望你能理解我所说的并且对你有帮助。
[更新]
好的,你的 xml 看起来像这样。
注意:我只是为此编写一个框架。
<!-- The main content view -->
<FrameLayout android:id="@+id/content_frame" />
<!-- The navigation drawer -->
<LinearLayout
android:layout_gravity="start"
android:orientation="horizontal">
<ListView
android:layout_weight="1"
android:id="@+id/list1">
</ListView>
<ListView
android:layout_weight="1"
android:id="@+id/list2">
</ListView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
现在在你的java端。考虑两个listview都被引用为list1和list2,并且您已经创建了两个适配器adapter1和adapter2。
让 Item 单击list1并应用如下逻辑...
list1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
// now here you can get which option is clicked from list1.
// using position and
int your_type = pos;
adapter2.filderDataAccordingToType(your_type);
// create the above method in your second adapter and pass your type like MyNews, City or any other.
// and apply the logic of filtering by passing type to your method
// your_type could be any data type i have take the integer.
// and after filtering data you can notify your adapter.
// so when the data of adpater gets changed your secondlistview get refreshed.
}
});
Run Code Online (Sandbox Code Playgroud)
就是这样。 我希望它对你有帮助。
| 归档时间: |
|
| 查看次数: |
6313 次 |
| 最近记录: |