我有两个列表视图,父列表视图具有Essay项目,其中包含“ 20篇论文标题”的子列表视图。单击Essay的标题时,将打开一个具有文本视图以显示文本的活动。我不想每20篇论文就做20项活动。当我打开任何子项目时,有什么办法,它仅显示该子项目的指定数据。 这是图片的例子
父母名单和描述性散文
[https://drive.google.com/file/d/1QksjP7hzpqmVCk_Y1ctwsDMYkijDHQPt/view?usp=sharing][1]
单击描述性论文后。它显示了Child EssayTitle列表
[https://drive.google.com/open?id=1NLbkrKD9c8yZb7rvapCxb-Na_lCVJf3P][2]
现在,单击“儿童列表”项的论文标题“ Call No Man Happy Till”。它显示完整答案
[https://docs.google.com/uc?export=download&id=1542uOZFzLx8vU7EMlsEhRaWZaguVTKHV ] [3]
我到不知道该怎么做的地方搜索。抱歉,但是我是android dev的新手。我刚刚创建了一个自定义适配器和一个数组列表
public class Writing extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.formenuitem);
ArrayList<MenuItems> essay = new ArrayList<>();
ArrayList<MenuItems> items = new ArrayList<>();
ArrayList<MenuItems> task2Item = new ArrayList<>();
//================= main items
items.add(new MenuItems("Descriptive Essay", "list of descriptive essay and solutions"));
items.add(new MenuItems("Essay 1", "More Essay list"));
items.add(new MenuItems("Type of Essay ", "How to start Essay Task 1, body-paragraph "));
items.add(new MenuItems("Task 2", "Solved essay "));
//show this list in when clicked on Descriotive essay item================================================================
task2Item.add(new MenuItems("Call No Man Happy Till","This essay about crime"));
task2Item.add(new MenuItems("Education","This essay about Education"));
task2Item.add(new MenuItems("University","This essay about University"));
task2Item.add(new MenuItems("Food","This essay about Food"));
task2Item.add(new MenuItems("Games","This essay about crime"));
task2Item.add(new MenuItems("Experience","This essay about crime"));
task2Item.add(new MenuItems("This is another essay","This essay about crime"));
task2Item.add(new MenuItems("This is another essay","This essay about crime"));
//======================set up for main item list
final ListAdapter adapter = new ListAdapter(this, items, R.color.category_numbers);
//setting adapter to have task 2 list
final ListAdapter task2list = new ListAdapter(Writing.this ,task2Item,R.color.category_numbers);
//creating variable to find list view for both
final ListView listView = findViewById(R.id.list);
final ListView task2 = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
// set up to click on the writing
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0){
// make clickable at position 0
task2.setAdapter(task2list);
task2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position==0){
Intent open = new Intent(Writing.this,ContentDisplay.class);
startActivity(open);
}
}
});
}
}
});
}
}
I just when I open essay item it leads to me to an essay title list and when I click on essay title it shows me whole answer
[1]: https://i.stack.imgur.com/HpgLL.jpg
[2]: https://i.stack.imgur.com/wc4wx.jpg
[3]: https://i.stack.imgur.com/yLqeg.jpg
答案 0 :(得分:0)
您需要一个自定义适配器。在适配器视图内实现onClick侦听器。对于位置,标记适配器视图并在侦听器中获取其标记。我希望您熟悉创建自定义适配器。 如果您需要更多帮助,我希望能提供帮助。