Advertisement
Guest User

Untitled

a guest
Mar 20th, 2013
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.18 KB | None | 0 0
  1. Recipedetails.java
  2. public class Recipedetails {
  3.    
  4.     public String getName() {
  5.         return name;
  6.     }
  7.     public void setName(String name) {
  8.         this.name = name;
  9.     }
  10.     public String getItemDescription() {
  11.         return itemDescription;
  12.     }
  13.     public void setItemDescription(String itemDescription) {
  14.         this.itemDescription = itemDescription;
  15.     }
  16.    
  17.    
  18.     public int getImageNumber() {
  19.         return imageNumber;
  20.     }
  21.     public void setImageNumber(int imageNumber) {
  22.         this.imageNumber = imageNumber;
  23.     }
  24.    
  25.     private String name ;
  26.     private String itemDescription;
  27.     private int imageNumber;
  28.    
  29.  
  30. }
  31.  
  32. ItmeListBasAdapter.java
  33. public class ItemListBaseAdapter extends BaseAdapter {
  34.     private static ArrayList<Recipedetails> itemDetailsrrayList;
  35.    
  36.     private Integer[] imgid = {
  37.                     R.drawable.vegeterian,
  38.                     R.drawable.nonveg,
  39.                     R.drawable.pickels,
  40.                     R.drawable.soup,
  41.                     R.drawable.sweets,
  42.                     R.drawable.cakes,
  43.                     R.drawable.icecreams,
  44.                     R.drawable.chinesevegdishes,
  45.                     R.drawable.chinesenonveg,
  46.                     R.drawable.chinesenoodles,
  47.                     R.drawable.chinesesoup,
  48.                     R.drawable.godhumaivegadai,
  49.                     R.drawable.soyamorekoozh,
  50.                     R.drawable.tomatokulambu,
  51.                     R.drawable.tomatoupma,
  52.                     R.drawable.vadanavratrispecial,
  53.                     R.drawable.eggkurma,
  54.                     R.drawable.milagu,
  55.                     R.drawable.rasam,
  56.                     R.drawable.vegetablekootu,
  57.                     R.drawable.avial,
  58.                     R.drawable.kothavarangaicurry,
  59.                     R.drawable.allepeyfishcurry,
  60.                     R.drawable.spicymadraschicken,
  61.                     R.drawable.prawns,
  62.                     R.drawable.keralachickenstew,
  63.                     R.drawable.nilgirichickenkorma,
  64.                     R.drawable.pepperchickencurry,
  65.                     R.drawable.chettiandchicken,
  66.                     R.drawable.prawnmasala,
  67.                     R.drawable.beeffry,
  68.                     R.drawable.crispyfish,
  69.                     R.drawable.amlapickle,
  70.                     R.drawable.avakaipickle,
  71.                     R.drawable.capsicumpickle,
  72.                     R.drawable.lemonpickle,
  73.                     R.drawable.onionpickle,
  74.                     R.drawable.mangopickle,
  75.                     R.drawable.tendermangopickle,
  76.                     R.drawable.tomatopickle,
  77.                     R.drawable.chillipickles,
  78.                     R.drawable.gingerpickle,
  79.                     R.drawable.garlicsoup,
  80.                     R.drawable.mixedvegsoup,
  81.                     R.drawable.chickenmanchowsoup,
  82.                     R.drawable.cleartomatosoup,
  83.                     R.drawable.sweetcornvegetablesoup,
  84.                     R.drawable.prawnandnoodlesoup,
  85.                     R.drawable.beetrootsoup,
  86.                     R.drawable.capsicumsoup,
  87.                     R.drawable.muttonsoup,
  88.                     R.drawable.spinachsoup,
  89.                     R.drawable.vegcurry,
  90.                     R.drawable.mushroommutter,
  91.                     R.drawable.alooparatha,
  92.                     R.drawable.daltadka,
  93.                     R.drawable.aloomethi,
  94.                     R.drawable.rajma,
  95.                     R.drawable.paneerbhujri,
  96.                     R.drawable.alooghobi,
  97.                     R.drawable.aloosabzi,
  98.                     R.drawable.kadhaipaneer,
  99.                     R.drawable.chickenwithbellpeppers,
  100.                     R.drawable.butterchicken,
  101.                     R.drawable.fishkorma,
  102.                     R.drawable.prawnfry,
  103.                     R.drawable.tandoorichicken,
  104.                     R.drawable.maccherjholfish,
  105.                     R.drawable.shamikabab,
  106.                     R.drawable.saagmeat,
  107.                     R.drawable.sindhichickenbiryani,
  108.                     R.drawable.punjabichickencurry,
  109.                     R.drawable.gulabjamun,
  110.                     R.drawable.basundi,
  111.                     R.drawable.peda,
  112.                     R.drawable.badhamhalwa,
  113.                     R.drawable.coconutburfi,
  114.                     R.drawable.kulfi,
  115.                     R.drawable.ladoo,
  116.                     R.drawable.mysorepak,
  117.                     R.drawable.ricekheer,
  118.                     R.drawable.badam,
  119.                     R.drawable.cauliflowersoup,
  120.                     R.drawable.cucumbersoup,
  121.                     R.drawable.tomatosoup,
  122.                     R.drawable.mulligatawnysoup,
  123.                     R.drawable.greenpeassoup,
  124.                     R.drawable.northindianmuttonsoup,
  125.                     R.drawable.chickennoodlesoup,
  126.                     R.drawable.spicybeansoup,
  127.                     R.drawable.eggdropsoup,
  128.                     R.drawable.springvegsoup,
  129.                     R.drawable.mushroomandseitan,
  130.                     R.drawable.tofuwith3spices,
  131.                     R.drawable.creamyvegpie,
  132.                     R.drawable.grilledvegmedley,
  133.                     R.drawable.bakedsquash,
  134.                     R.drawable.africanchickenstew,
  135.                     R.drawable.westafricanchicken,
  136.                     R.drawable.africanyamsoup,
  137.                     R.drawable.chickenchilliroast,
  138.                     R.drawable.chilliblackbeans,
  139.                     R.drawable.williecake,
  140.                     R.drawable.pumpkingingercupcakes,
  141.                     R.drawable.doublelayerpumpkincheesecake,
  142.                     R.drawable.carrotcake,
  143.                     R.drawable.sexcake,
  144.                     R.drawable.chocolatechipicecream,
  145.                     R.drawable.cookieicecream,
  146.                     R.drawable.cinnamonicecream,
  147.                     R.drawable.appleicecream,
  148.                     R.drawable.walnut,
  149.                     R.drawable.chineseaubergins,
  150.                     R.drawable.spicycucumber,
  151.                     R.drawable.chinesemushrooms,
  152.                     R.drawable.chinesegobi,
  153.                     R.drawable.spicytofu,
  154.                     R.drawable.chinesetilchicken,
  155.                     R.drawable.chickenmoongali,
  156.                     R.drawable.sweetsourchicken,
  157.                     R.drawable.cherrychicken,
  158.                     R.drawable.mymasalachicken,
  159.                     R.drawable.coldseasamenoodles,
  160.                     R.drawable.sobanoodles,
  161.                     R.drawable.noodleswithtofu,
  162.                     R.drawable.chinesevegandbeef,
  163.                     R.drawable.noodleswithpepper,
  164.                     R.drawable.jhingasoup,
  165.                     R.drawable.masalachickensoup,
  166.                     R.drawable.cabbagesoup,
  167.                     R.drawable.chinesepumpkinsoup,
  168.                     R.drawable.baconsoup,
  169.                    
  170.                    
  171.                     };
  172.    
  173.    
  174.    
  175.     private LayoutInflater l_Inflater;
  176.  
  177.     public ItemListBaseAdapter(Context context, ArrayList<Recipedetails> results) {
  178.             itemDetailsrrayList = results;
  179.             l_Inflater = LayoutInflater.from(context);
  180.     }
  181.  
  182.     public int getCount() {
  183.             return itemDetailsrrayList.size();
  184.     }
  185.  
  186.     public Object getItem(int position) {
  187.             return itemDetailsrrayList.get(position);
  188.     }
  189.  
  190.     public long getItemId(int position) {
  191.             return position;
  192.     }
  193.  
  194.     public View getView(int position, View convertView, ViewGroup parent) {
  195.             ViewHolder holder;
  196.             if (convertView == null) {
  197.                     convertView = l_Inflater.inflate(R.layout.item_details_view, null);
  198.                     holder = new ViewHolder();
  199.                     holder.txt_itemName = (TextView) convertView.findViewById(R.id.name);
  200.                     holder.txt_itemDescription = (TextView) convertView.findViewById(R.id.itemDescription);
  201.                     holder.itemImage = (ImageView) convertView.findViewById(R.id.photo);
  202.  
  203.                     convertView.setTag(holder);
  204.             } else {
  205.                     holder = (ViewHolder) convertView.getTag();
  206.             }
  207.            
  208.             holder.txt_itemName.setText(itemDetailsrrayList.get(position).getName());
  209.             holder.txt_itemDescription.setText(itemDetailsrrayList.get(position).getItemDescription());
  210.             holder.itemImage.setImageResource(imgid[itemDetailsrrayList.get(position).getImageNumber() - 1]);
  211.             return convertView;
  212.     }
  213.     public synchronized   void refreshAdapter(ArrayList<Recipedetails> items) {
  214.         itemDetailsrrayList.clear();
  215.         itemDetailsrrayList.addAll(items);
  216.        notifyDataSetChanged();
  217.     }
  218.  
  219.     static class ViewHolder {
  220.             TextView txt_itemName;
  221.             TextView txt_itemDescription;
  222.             ImageView itemImage;
  223.     }
  224.  
  225.    
  226.  
  227. }
  228. Soutindian.java
  229. public class SouthIndian extends Activity {
  230.     ItemListBaseAdapter _itemListAdapter;
  231.      @Override
  232.         public void onCreate(Bundle savedInstanceState) {
  233.             super.onCreate(savedInstanceState);
  234.             setContentView(R.layout.main);
  235.            
  236.             ArrayList<Recipedetails> image_details = new ArrayList<Recipedetails>();
  237.            
  238.             _itemListAdapter = new ItemListBaseAdapter(this, image_details);
  239.  
  240.             final ListView lv1 = (ListView) findViewById(R.id.listV_main);
  241.             lv1.setAdapter(_itemListAdapter);
  242.            
  243.             lv1.setOnItemClickListener(new OnItemClickListener() {
  244.                     @Override
  245.                     public void onItemClick(AdapterView<?> a, View v, int position, long id) {
  246.                             Object o = lv1.getItemAtPosition(position);
  247.                             Recipedetails obj_itemDetails = (Recipedetails)o;
  248.                             Toast.makeText(SouthIndian.this, "You have chosen : " + " " +      obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
  249.                            
  250.                             switch(obj_itemDetails.getImageNumber())
  251.                             {
  252.                                 case 1:
  253.                                      Intent newActivity = new Intent(SouthIndian.this,
  254.                                                      AndroidTabLayoutActivity.class);    
  255.                          startActivity(newActivity);
  256.                                     break;
  257.                                    
  258.                                 case 2:
  259.                                     Intent new1Activity = new Intent(SouthIndian.this,
  260.                                                     AndroidTabLayoutActivity1.class);    
  261.                                 startActivity(new1Activity);
  262.                                     break;
  263.                                    
  264.                                 case 3:
  265.                                     Intent new2Activity = new Intent(SouthIndian.this,
  266.                                                     AndroidTabLayoutActivity2.class);    
  267.                                 startActivity(new2Activity);
  268.                                     break;
  269.                                    
  270.                                 case 4:
  271.                                     Intent new3Activity = new Intent(SouthIndian.this,
  272.                                                     AndroidTabLayoutActivity3.class);    
  273.                                 startActivity(new3Activity);
  274.                                     break;        
  275.                                    
  276.                                default:
  277.                                        Toast.makeText(SouthIndian.this, "Wrong Input", Toast.LENGTH_LONG).show();
  278.                             }
  279.                            
  280.                     }
  281.             });
  282.  
  283.             refreshYourAdapter(GetSearchResults());
  284.         }
  285.        
  286.         // THIS IS WHAT IT SHOULD LOOK LIKE MORE OR LESS. THIS IS AS MUCH AS I CAN HELP
  287.  
  288.         private void refreshYourAdapter(final ArrayList<Recipedetails> items) {
  289.              //this is what I meant. The error clearly states you are not updating the adapter on the UI thread
  290.              runOnUiThread(new Runnable() {
  291.                  public void run() {
  292.                      _itemListAdapter.refreshAdapter(items);
  293.                  }
  294.              });
  295.         }
  296.  
  297.         private ArrayList<Recipedetails> GetSearchResults(){
  298.             ArrayList<Recipedetails> results = new ArrayList<Recipedetails>();
  299.            
  300.             Recipedetails item_details = new Recipedetails();
  301.             item_details.setName("Vegterian");
  302.             item_details.setItemDescription("Recipes made by raw materials");
  303.                 item_details.setImageNumber(1);
  304.             results.add(item_details);
  305.            
  306.             item_details = new Recipedetails();
  307.             item_details.setName("Non-Vegterian");
  308.             item_details.setItemDescription("Flesh of sweet animals");
  309.             item_details.setImageNumber(2);
  310.             results.add(item_details);
  311.            
  312.             item_details = new Recipedetails();
  313.             item_details.setName("Pickels");
  314.             item_details.setItemDescription("Touchable dish  by Homemade");
  315.             item_details.setImageNumber(3);
  316.             results.add(item_details);
  317.            
  318.             item_details = new Recipedetails();
  319.             item_details.setName("Soups");
  320.             item_details.setItemDescription("Startup for our food");
  321.                 item_details.setImageNumber(4);
  322.             results.add(item_details);
  323.            
  324.             return results;
  325.         }
  326. }
  327. Northindian.java
  328. public class NorthIndian  extends Activity {
  329.      ItemListBaseAdapter _itemListAdapter;
  330.    
  331.    
  332.      @Override
  333.         public void onCreate(Bundle savedInstanceState) {
  334.             super.onCreate(savedInstanceState);
  335.             setContentView(R.layout.main);
  336.            
  337.             ArrayList<Recipedetails> image_details = new ArrayList<Recipedetails>();
  338.                
  339.             _itemListAdapter = new ItemListBaseAdapter(this, image_details);
  340.            
  341.             final ListView lv1 = (ListView) findViewById(R.id.listV_main);
  342.             lv1.setAdapter(_itemListAdapter);
  343.            
  344.             lv1.setOnItemClickListener(new OnItemClickListener() {
  345.                 @Override
  346.                 public void onItemClick(AdapterView<?> a, View v, int position, long id) {
  347.                     Object o = lv1.getItemAtPosition(position);
  348.                     Recipedetails obj_itemDetails = (Recipedetails)o;
  349.                     Toast.makeText(NorthIndian.this, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
  350.                    
  351.                     switch(obj_itemDetails.getImageNumber())
  352.                     {
  353.                         case 1:
  354.                              Intent newActivity = new Intent(NorthIndian.this,
  355.                                      AndroidTabLayoutActivity4.class);    
  356.                              startActivity(newActivity);
  357.                             break;
  358.                            
  359.                         case 2:
  360.                             Intent new1Activity = new Intent(NorthIndian.this,
  361.                                     AndroidTabLayoutActivity5.class);    
  362.                             startActivity(new1Activity);
  363.                             break;
  364.                            
  365.                         case 5:
  366.                             Intent new2Activity = new Intent(NorthIndian.this,
  367.                                     AndroidTabLayoutActivity6.class);    
  368.                             startActivity(new2Activity);
  369.                             break;
  370.                            
  371.                         case 4:
  372.                             Intent new3Activity = new Intent(NorthIndian.this,
  373.                                     AndroidTabLayoutActivity7.class);    
  374.                             startActivity(new3Activity);
  375.                             break;     
  376.                            
  377.                        default:
  378.                            Toast.makeText(NorthIndian.this, "Wrong Input", Toast.LENGTH_LONG).show();
  379.                     }
  380.                 }  
  381.             });
  382.             refreshYourAdapter(GetSearchResults());
  383.         }
  384.       private void refreshYourAdapter(final ArrayList<Recipedetails> items) {
  385.           //this is what I meant. The error clearly states you are not updating the adapter on the UI thread
  386.           runOnUiThread(new Runnable() {
  387.               public void run() {
  388.                   _itemListAdapter.refreshAdapter(items);
  389.               }
  390.           });
  391.      }
  392.        
  393.         private ArrayList<Recipedetails> GetSearchResults(){
  394.             ArrayList<Recipedetails> results = new ArrayList<Recipedetails>();
  395.            
  396.             Recipedetails item_details = new Recipedetails();
  397.             item_details.setName("Vegterian");
  398.             item_details.setItemDescription("Recipes made by raw materials");
  399.             item_details.setImageNumber(1);
  400.             results.add(item_details);
  401.            
  402.             item_details = new Recipedetails();
  403.             item_details.setName("Non-Vegterian");
  404.             item_details.setItemDescription("Flesh of sweet animals");
  405.             item_details.setImageNumber(2);
  406.             results.add(item_details);
  407.            
  408.             item_details = new Recipedetails();
  409.             item_details.setName("Sweets");
  410.             item_details.setItemDescription("Tasty sweets made from indians");
  411.             item_details.setImageNumber(5);
  412.             results.add(item_details);
  413.            
  414.             item_details = new Recipedetails();
  415.             item_details.setName("Soups");
  416.             item_details.setItemDescription("Startup for our food");
  417.             item_details.setImageNumber(4);
  418.             results.add(item_details);
  419.            
  420.            
  421.            
  422.            
  423.             return results;
  424.         }
  425.  
  426. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement