Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2012
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. package com.pablotest.pack;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.graphics.Color;
  6. import android.os.Bundle;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.widget.AdapterView;
  11. import android.widget.ArrayAdapter;
  12. import android.widget.ImageView;
  13. import android.widget.ListView;
  14. import android.widget.TextView;
  15. import android.widget.AdapterView.OnItemClickListener;
  16.  
  17. public class AlphabetListDemo extends Activity {
  18. //String of alphabets //
  19. String[] alphabts = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
  20. ListView L1, L2;
  21. myAdapter myadp;
  22. myAdapter2 myadp2;
  23. String prod_arr[] = {};
  24.  
  25. @Override
  26. public void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28. setContentView(R.layout.main);
  29.  
  30. L1 = (ListView)findViewById(R.id.list1);
  31. L2 = (ListView)findViewById(R.id.list2);
  32.  
  33. myadp = new myAdapter(this,alphabts);
  34. L2.setAdapter(myadp);
  35.  
  36. // initial populating //
  37. setProducts(0);
  38.  
  39. L2.setOnItemClickListener(new OnItemClickListener(){
  40. @Override
  41. public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
  42. long arg3) {
  43. setProducts(arg2);
  44. }
  45. });
  46.  
  47. }
  48.  
  49. public void setProducts(int number){
  50. prod_arr = new String[25];
  51. // adding some dummy data //
  52. for(int i = 0; i < 25 ; i++){
  53. prod_arr[i] = "Product : " + alphabts[number] + i;
  54. }
  55. //setting the adapter in listview //
  56. myadp2 = new myAdapter2(AlphabetListDemo.this,prod_arr);
  57. L1.setAdapter(myadp2);
  58. }
  59.  
  60. class myAdapter extends ArrayAdapter<String>
  61. {
  62. TextView label;
  63. ImageView image;
  64. View row;
  65. public myAdapter(Context context,String[] arr)
  66. {
  67. super(context, android.R.layout.simple_list_item_1, arr);
  68. }
  69.  
  70. public View getView(final int position, View convertView, ViewGroup parent)
  71. {
  72. try{
  73. LayoutInflater inflater=getLayoutInflater();
  74. row = inflater.inflate(R.layout.lv_rows, parent, false);
  75. label = (TextView)row.findViewById(R.id.item_title);
  76. label.setText(alphabts[position]);
  77. label.setTextColor(Color.YELLOW);
  78. }catch(Exception e){
  79.  
  80. }
  81. return row;
  82. }
  83. }
  84. // adapter for second list.....
  85. class myAdapter2 extends ArrayAdapter<String>
  86. {
  87. TextView label;
  88. ImageView image;
  89. View row;
  90. public myAdapter2(Context context,String[] arr)
  91. {
  92. super(context, android.R.layout.simple_list_item_1, arr);
  93. }
  94.  
  95. public View getView(final int position, View convertView, ViewGroup parent)
  96. {
  97. try{
  98. LayoutInflater inflater=getLayoutInflater();
  99. row = inflater.inflate(R.layout.lv_rows, parent, false);
  100. label = (TextView)row.findViewById(R.id.item_title);
  101. label.setText(prod_arr[position]);
  102. label.setTextColor(Color.WHITE);
  103. }catch(Exception e){
  104.  
  105. }
  106. return row;
  107. }
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement