Two ListView linkage

Source: Internet
Author: User

Package Com.mttz;

Import java.util.ArrayList;
Import java.util.List;

Import Com.mttz.adapter.CaiDanADP;
Import Com.mttz.bean.ShopDTO;

Import Android.graphics.Color;
Import Android.os.Bundle;
Import android.support.v4.app.Fragment;
Import Android.support.v4.app.FragmentManager;
Import Android.support.v4.app.FragmentPagerAdapter;
Import Android.support.v4.view.ViewPager;
Import Android.support.v4.view.ViewPager.OnPageChangeListener;
Import Android.util.Log;
Import android.view.Gravity;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.AbsListView;
Import Android.widget.AdapterView;
Import Android.widget.ArrayAdapter;
Import Android.widget.BaseAdapter;
Import Android.widget.ImageView;
Import Android.widget.LinearLayout;
Import Android.widget.ListView;
Import Android.widget.ScrollView;
Import Android.widget.TextView;

public class Caipinfragment extends fragment{

Begin
ListView ListView, ListView2;
/**
* Originally want to do the title stay at the top, don't think about it
*/
TextView TextView;
/**
* The array to use for the left ListView
*/
string[] arr = new string[] {"Fast food", "supermarket", "fruit", "fresh", "pharmacy", "More"};


string[] arr2 = new string[] {"Fast food", "dumplings", "noodles", "rice noodles", "chili", ""};
string[] Arr3 = new string[] {"Supermarket", "urgent", "use", "money", "find", "I", "we"};
string[] Arr4 = new string[] {"Fruit", "put", "paragraph", "Fast", "sum"};
string[] Arr5 = new string[] {"Fresh", "degree", "High", "none", "Required", "low", "pressure",
"Food"};
string[] Arr6 = new string[] {"Pharmacy", "Lian", "department", "Electricity"};
string[] arr7 = new string[] {"More", "words", "x", "X", "X", "X", "X",
"X", "X", "X", "Beauty", "Pass", "cast", "capital"};

string[][] Arr8 = new string[][] {arr2, ARR3, ARR4, ARR5, ARR6, arr7};

/**
* Used to store food array
*/
List<string> list;

/**
* Used to record each 1 2 3 4 5 6 position on the right side of the ListView;
*/
list<integer> nums = new arraylist<integer> ();
End


Private ListView Cp_caidan_lv,cp_caipin_lv;



@Override
Public View Oncreateview (layoutinflater inflater, ViewGroup container,
Bundle savedinstancestate) {
View Rootview = Inflater.inflate (R.layout.fragment_caipin,container, false);
Initwithview (Rootview);
Initview (Rootview);

return rootview;
}


private void Initwithview (view view) {
CP_CAIDAN_LV = (ListView) View.findviewbyid (R.ID.CP_CAIDAN_LV);//left menu bar
CP_CAIPIN_LV = (ListView) View.findviewbyid (R.ID.CP_CAIDAN_LV);//Right Side menu bar
//
//
// }
//



private void Initview (view view)
{
TextView = (TextView) Findviewbyid (R.ID.TEXTVIEW1);
ListView = (ListView) View.findviewbyid (R.ID.CP_CAIDAN_LV);

list<string> caipinlv= new arraylist<string> ();
List = new arraylist<string> ();

for (int j = 0; J < Arr.length; J + +)
{

Caipinlv.add (Arr[j]);

}

CAIDANADP ADP = new Caidanadp (CAIPINLV, getactivity ());
Listview.setadapter (ADP);


List = new arraylist<string> ();

for (int j = 0; J < Arr8.length; J + +)
{
for (int j2 = 0; J2 < arr8[j].length; j2++)
{
List.add (Arr8[j][j2]);
}
}

for (int i = 0; i < arr8.length; i++)
{
if (i = = 0)
{
Nums.add (0);
} else if (i > 0 && i < arr8.length)
{
int num = 0;
for (int j = 0; J < i; J + +)
{
num = num + arr8[j].length;

}
Nums.add (num);
}
}


ListView2 = (ListView) View.findviewbyid (R.ID.CP_CAIPIN_LV);
Listview2.setadapter (New Myadapter ());

/**
*
* Judging the ListView slide
* */
Listview2.setonscrolllistener (New Abslistview.onscrolllistener ()
{

@Override
public void onscrollstatechanged (Abslistview view, int scrollstate)
{

}

@Override
public void Onscroll (Abslistview view, int firstvisibleitem,
int visibleitemcount, int totalitemcount)
{
if (Nums.contains (Firstvisibleitem) && listview.getchildcount () > 0)
{

for (int i = 0; i < Listview.getchildcount (); i++)
{
if (i = = Nums.indexof (Firstvisibleitem))
{
Listview.getchildat (i). SetBackgroundColor (
Color.rgb (200, 200, 200));
} else
{
Listview.getchildat (i). SetBackgroundColor (color.transparent);

}


}



}
}
});

Listview.setonitemclicklistener (New Adapterview.onitemclicklistener ()
{
@Override
public void Onitemclick (adapterview<?> parent, view view, int position,
Long ID)
{
for (int i = 0; i < Listview.getchildcount (); i++)
{
if (i = = position)
{
View.setbackgroundcolor (Color.rgb (255, 250, 250));
} else
{
View.setbackgroundcolor (Color.rgb (200, 200, 200));
}
}

Listview2.setselection (Nums.get (position));

}
});

}

Class Myadapter extends Baseadapter
{
Private Layoutinflater Inflater;

@Override
public int GetCount ()
{
return List.size ();
}

@Override
Public Object getItem (int position)
{
return List.get (position);
}

@Override
public long getitemid (int position)
{
return position;
}

@Override
Public View GetView (int position, view Convertview, ViewGroup parent)
{
TextView TextView = new TextView (getactivity ());
Textview.settext (List.get (position));
Textview.setgravity (gravity.center_vertical);
Textview.setminheight (200);
//
//
if (nums.contains (position))
//{
Textview.setbackgroundcolor (Color.argb (80,80, 80, 80));
//}


if (Convertview = = null) {
Inflater = Layoutinflater.from (Getactivity ());
Convertview = inflater.inflate (R.layout.shop_item, NULL);


TextView shop_name = (TextView) Convertview.findviewbyid (r.id.shop_name);
ImageView Shoplogo = (ImageView) Convertview.findviewbyid (R.id.shop_logo);
Convertview.settag (holder);
Shop_name.settext (List.get (position));
Shoplogo.setbackgroundresource (R.DRAWABLE.ELEME_SJM);
if (nums.contains (position))
{
Convertview = inflater.inflate (r.layout.goods_details, NULL);
Convertview.setg
TextView CP = (TextView) Convertview.findviewbyid (r.id.cp_root);
Cp.settext (List.get (position));
Cp.settextcolor (Color.rgb (255,250,250));
Convertview.setbackgroundcolor (Color.rgb (200, 200, 200));
return convertview;
}else {
return convertview;
}
//}
//
//
if (minfo!=null) {
String shopname= minfo.getshopname ();
String imageUrl = Minfo.getshoplogo ();




}

}
}

Two ListView linkage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.