Listview on android tablet
I have a tablet layout of two listviews, one right and one left. When I click on a group (item of left list), groups get displayed in the other list (groupsList). Now I need to display another layout when I click on the groupslist in that specific area. So how to proceed?
Below is my code:-
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[] {"test@test.com","","","kathy.buhler@excellus.com"};
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;
}
}
}
In terms of displaying the third list, it's actually very easy to do, and fit into your pattern. In your layout file, define the third list, but sset its visibility to gone, so that it cannot yet be seen. Now, when you get a click within the second list, you can then set the visibility of the third list to make it visible:
Lister.setVisibility (View.VISIBLE) ;
精彩评论