如何隐藏列表视图并在android中显示另一个布局?

时间:2013-12-07 10:47:02

标签: android listview layout

我有一个简单的适配器列表视图如果我点击listview项目列表视图shoud隐藏和另一个布局shoud show

我试过这样做 ListView代码

    final String[] questions = new String[] {
       "1. What was banned in 393 A.D. as it was considered an unholy ritual by the Romans?", 
      "2. The musical instrument ‘veena’ is made from the wood of which tree?",
      "3. The movie Jurassic Park was based on a novel of the same name. Can you name the author?", 
      "4. Which famous personality was assassinated on 31st October 1984 by Satwant Singh and Beant Singh?", 
      "5. Who owns the newspaper Saakshi and used it to campaign in the media?", 
      "6. The filament of a common light bulb is generally made from which material?", 
      "7. Who was the last Tsar (king) of Russia who along with his entire family was murdered in the Russian revolution in 1917?", 
      "8. Who in Indian sports is known as the Flying Sikh?", 
      "9. In internet terminology we often come across the term URL. What does URL stand for?", 
     "10. In world of children literature, who is the famous sister of Anastasia and Drizella?" };

     for (int i = 0; i < questions.length; i++) {

        HashMap<String, String> temp = new HashMap<String, String>();
        temp.put("question", questions[i]);
        TotalQuestion.add(temp);
    }
    SimpleAdapter sa = new SimpleAdapter(getApplicationContext(), 
                         TotalQuestion, R.layout.activity_question, new String[] {
                         "question" }, new int[] { R.id.text_question });
    lv.setAdapter(sa);`

我正试图在listview onItemclick中隐藏listview 隐藏列表视图的代码是

    View myView = findViewById(R.id.linearLayout1);//linearLayout1 Contains listview textbox
    ViewGroup parent = (ViewGroup) myView.getParent();
    parent.removeView(myView);

    LinearLayout hiddenLayout = (LinearLayout) findViewById(R.id.hiddenLayout);
            if (hiddenLayout == null) {
                // Inflate the Hidden Layout Information View
                LinearLayout myLayout = (LinearLayout) findViewById(R.id.linearLayout2);
                View hiddenInfo = getLayoutInflater().inflate(R.layout.hidden, myLayout, false);
                myLayout.addView(hiddenInfo);
            }

1 个答案:

答案 0 :(得分:0)

如果你想要改变布局,你可以在你想要的每个地方再次呼叫setContentView();(在你的应用程序中这必须调用项目选择列表),但在你的场景中我认为你需要在其他地方的位置activity,所以创建另一个类并使用intent调用该类,并使用它传递您的数据。