2011-06-14 250 views
0

我有兩個列表視圖,一個右和一個左側的平板電腦佈局。當我點擊一個組(左列表項目)時,組將顯示在另一個列表(groupsList)中。現在我需要在該特定區域中單擊組列表時顯示另一個佈局。 那麼如何繼續?Android平板電腦Listview

下面是我的代碼: -

package com.list.viewer; 

import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.BaseAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.AdapterView.OnItemClickListener; 

public class HealthPlan extends Activity 
{ 

private String[] list1 = { "Group", "Opportunities", "Contacts", "Activities" , "Quotes"}; 
private String[] list2 = { "", "", "", "" , ""}; 

private Integer[] imgid = {R.drawable.accounts,R.drawable.s,R.drawable.contacts, 
     R.drawable.activities ,R.drawable.s}; 

static final Integer[] aimgid = {R.drawable.activities_60,R.drawable.activities_60,R.drawable.activities_60, 
    R.drawable.activities_60,R.drawable.activities_60}; 

static final String[] a1 = new String[] {"1-96XO56","1-96XOPL","1-96XOMR","1-96XOKM"}; 

static final String[] a2 = new String[] {"Open","Closed","Cancelled","Open"}; 

static final Integer[] cimgid = {R.drawable.contacts_60,R.drawable.contacts_60,R.drawable.contacts_60, 
    R.drawable.contacts_60 ,R.drawable.contacts_60}; 

static final String[] c1 = new String[] {"Denning","Guido","Castro","Heath"}; 

static final String[] c2 = new String[] {"[email protected]","","","[email protected]"}; 

static final Integer[] gimgid = {R.drawable.accounts_60,R.drawable.accounts_60,R.drawable.accounts_60, 
    R.drawable.accounts_60 ,R.drawable.accounts_60}; 

static final String[] g1 = new String[] {"La Maison Blanche Bakery","(NSCC) FRONTIER INFORMATI", 
    "american Diamond Tool,Inc","OCH Test 20100831"}; 

static final String[] g2 = new String[] {"PRVS - Private Sector","PBLS - Public Sector","PRVS - Private Sector","NATL - National Account"}; 

static final Integer[] qimgid = {R.drawable.health,R.drawable.health,R.drawable.health, 
    R.drawable.health,R.drawable.health}; 

static final String[] q1 = new String[] {"1-7LY9JK","1-7GRMRO","1-7FCJBR","1-7GRMP4"}; 

static final String[] q2 = new String[] {"In-Progress","Created","Install In Progress", 
    "Installed"}; 

static final Integer[] oimgid = {R.drawable.health,R.drawable.health,R.drawable.health, 
    R.drawable.health,R.drawable.health}; 

static final String[] o1 = new String[] {"Long Term Care","HMO Blue Choice Value", 
    "Drug","Long Term Care"}; 

static final String[] o2 = new String[] {"New Business - Exclusive", 
    "Win Exclusive","New Business - Nonexclusive","Change Product/Service"}; 

private ListView lister1; 
private ListView lister2; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    lister1 = (ListView) findViewById(R.id.ListView1); 
    lister2 = (ListView) findViewById(R.id.ListView2); 

    ItemsAdapter itemsAdapter = new ItemsAdapter(HealthPlan.this, 
      R.layout.row, list1 , list2,imgid); 
    lister1.setAdapter(itemsAdapter); 

    lister2.setAdapter(new ItemsAdapter(HealthPlan.this, 
      R.layout.row, g1 , g2,gimgid)); 

    lister2.setOnItemClickListener(new OnItemClickListener() 
    { 
     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, int position, 
       long arg3) 
     { 


     } 

    }); 

    lister1.setOnItemClickListener(new OnItemClickListener() 
    { 
     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, 
       int position, long arg3) 
     { 
      String[] lister = null; 
      String[] lister1 = null; 
      Integer[] image = null; 
      switch (position) 
      { 
      case 0: 
       lister = g1; 
       lister1 = g2; 
       image = gimgid; 
       break; 
      case 1: 
       lister = o1; 
       lister1 = o2; 
       image = oimgid; 
       break; 
      case 2: 
       lister = c1; 
       lister1 = c2; 
       image = cimgid; 
       break; 
      case 3: 
       lister = a1; 
       lister1 = a2; 
       image = aimgid; 
       break; 
      case 4: 
       lister = q1; 
       lister1 = q2; 
       image = qimgid; 
       break; 
      default: 
       lister = g1; 
       lister1 = g2; 
       image = gimgid; 
      } 
      lister2.setAdapter(new ItemsAdapter(HealthPlan.this, 
        R.layout.row, lister , lister1 ,image)); 
     } 
    }); 
} 

private class ItemsAdapter extends BaseAdapter 
{ 
    String[] items; 
    String[] items1; 
    Integer[] images; 

    public ItemsAdapter(Context context, int textViewResourceId,String[] items,String[] items1,Integer[] images) 
    { 
     this.items = items; 
     this.items1 = items1; 
     this.images=images; 
    } 

    @Override 
    public View getView(final int position, View convertView, ViewGroup parent) 
    { 
     TextView mDescription; 
     TextView mDescription1; 
     View view = convertView; 
     ImageView image; 

     if (view == null) 
     { 
      LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      view = vi.inflate(R.layout.row, null); 
     } 

     image = (ImageView) view.findViewById(R.id.icon); 
     mDescription = (TextView) view.findViewById(R.id.tt1); 
     mDescription1 = (TextView) view.findViewById(R.id.tt2); 
     mDescription.setText(items[position]); 
     mDescription1.setText(items1[position]); 
     image.setImageResource(images[position]); 
     return view; 
    } 

    public int getCount() 
    { 
     return items.length; 
    } 

    public Object getItem(int position) 
    { 
     return position; 
    } 

    public long getItemId(int position) 
    { 
     return position; 
    } 
} 

}

回答

0

在顯示第三列表而言,它實際上是很容易做到的,並適合你的模式。在您的佈局文件中,定義第三個列表,但將其可見性設置爲消失,以使其尚未顯示。現在,當您在第二個列表中獲得點擊時,可以設置第三個列表的可見性以使其可見:

Lister.setVisibility (View.VISIBLE) ;