daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Sep 14th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. preview/detail of single list on custom list view in android
  2. try {
  3.  
  4.       //*** Getting Array of Attributes
  5.             attributes = jsonreturn.getJSONObject(TAG_ATTRIBUTE);
  6.             String status = attributes.getString(TAG_VALIDCODE);
  7.             JSONObject invoices = jsonreturn.getJSONObject(TAG_INVOICELIST);
  8.             JSONArray invoice = invoices.getJSONArray(TAG_INVOICE);
  9.  
  10.             if(status.equals("200")){
  11.      // looping through All Invoice
  12.        for(int i = 0; i < invoice.length(); i++)
  13.          {
  14.  
  15.  
  16.             JSONObject c = invoice.getJSONObject(i);
  17.  
  18.      //***** Storing each JSON item in variable
  19.             JSONObject client = c.getJSONObject(TAG_CLIENT);
  20.             String organization = client.getString(TAG_ORGANIZATION);
  21.             String invoiceno = c.getString(TAG_ID);
  22.             String date = c.getString(TAG_DATE);
  23.             String currency = c.getString(TAG_CURRENCY);
  24.             String outstanding = c.getString(TAG_OUTSTANDING);
  25.             String invoice_status = c.getString(TAG_STATUS);
  26.             invoice_id = c.getString(TAG_INVOICE_ID);
  27.  
  28.  
  29.  
  30.     //**** creating new HashMap
  31.  
  32.             HashMap<String, String> map = new HashMap<String, String>();
  33.  
  34.    //*** adding each child node to HashMap key => value
  35.             map.put(TAG_ORGANIZATION, organization);
  36.             map.put(TAG_ID, invoiceno);
  37.             map.put(TAG_DATE, date);
  38.             map.put(TAG_CURRENCY, currency);
  39.             map.put(TAG_OUTSTANDING, outstanding);
  40.             map.put(TAG_STATUS, invoice_status);
  41.             map.put(TAG_INVOICE_ID, invoice_id);
  42.  
  43.   //**** adding HashList to ArrayList
  44.  
  45.             invoiceList.add(map);
  46.  
  47.             }
  48.        }
  49.  
  50.        else{
  51.             Toast.makeText(this, "Invalid Details", 1000).show();       }
  52.  
  53.  
  54.     }
  55.            catch (JSONException e)
  56.            {
  57.            e.printStackTrace();
  58.            }
  59.  
  60.      /**
  61.      Updating parsed JSON data into ListView
  62.      * */
  63.  
  64.     InvoiceListAdapter invoiceadapter = new InvoiceListAdapter(this, invoiceList);
  65.  
  66.     mListView.setAdapter(invoiceadapter);
  67.  
  68.  //****** Launching new screen on Selecting Single ListItem
  69.  
  70.  mListView.setOnItemClickListener(new OnItemClickListener() {
  71.  
  72.  
  73.         public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  74.         {
  75.             // getting values from selected ListItem
  76.  
  77.             //--String date = ((TextView) view.findViewById(R.id.date)).getText().toString();
  78.             //--String status = ((TextView) view.findViewById(R.id.invoicestatus)).getText().toString();
  79.  
  80.             // Starting new intent
  81.             Intent in = new Intent(getApplicationContext(), PreviewInvoice.class);
  82.             in.putExtra("myinvoiceid", invoice_id);
  83.             in.putExtra("uniquetoken", tokenid);
  84.            //-- in.putExtra(TAG_DATE, date);
  85.             //---in.putExtra(TAG_STATUS, status);
  86.             startActivity(in);
  87.         }
  88.     });
  89.    
  90. public class InvoiceListAdapter extends BaseAdapter {
  91.  
  92. //--private Activity activity;
  93. private ArrayList<HashMap<String, String>> data;
  94. private static LayoutInflater inflater=null;
  95.  
  96. public InvoiceListAdapter(ManageInvoice manageInvoice, ArrayList<HashMap<String, String>> invoiceList) {
  97.    //-- activity = manageInvoice;
  98.     data=invoiceList;
  99.  
  100.     inflater = (LayoutInflater)manageInvoice.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  101.  
  102. }
  103.  
  104. public int getCount() {
  105.     if(null==data){
  106.         return 0;
  107.     }
  108.     return data.size();
  109. }
  110.  
  111. public Object getItem(int position) {
  112.     if(null==data || data.size()<=position){
  113.         return null;
  114.     }
  115.     return data.get(position);
  116. }
  117.  
  118. public long getItemId(int position) {
  119.     return position;
  120. }
  121.  
  122. public View getView(int position, View convertView, ViewGroup parent)
  123. {
  124.  
  125.     View vi=convertView;
  126.     if(convertView==null)
  127.  
  128.     vi = inflater.inflate(R.layout.invoice_list, null );
  129.  
  130.     TextView title = (TextView)vi.findViewById(R.id.organization);
  131.     TextView invoiceId = (TextView)vi.findViewById(R.id.invoice_id);
  132.     TextView date = (TextView)vi.findViewById(R.id.date);
  133.     TextView currency = (TextView)vi.findViewById(R.id.currency);
  134.     TextView currencyvalue = (TextView)vi.findViewById(R.id.outstanding);
  135.     TextView status = (TextView)vi.findViewById(R.id.invoice_status);
  136.    // ImageView thumb_image=(ImageView)vi.findViewById(R.id.invoice_status);
  137.  
  138.     HashMap<String, String> Invoice = new HashMap<String, String>();
  139.     Invoice = data.get(position);
  140.  
  141.     // Setting all values in listview
  142.     title.setText(Invoice.get(ManageInvoice.TAG_ORGANIZATION));
  143.     invoiceId.setText(Invoice.get(ManageInvoice.TAG_ID));
  144.     date.setText(Invoice.get(ManageInvoice.TAG_DATE));
  145.     currency.setText(Invoice.get(ManageInvoice.TAG_CURRENCY));
  146.     currencyvalue.setText(Invoice.get(ManageInvoice.TAG_OUTSTANDING));
  147.     status.setText(Invoice.get(ManageInvoice.TAG_STATUS));
  148.  
  149.  
  150.     return vi;
  151. }
  152.  
  153. public JSONArray get(int position) {
  154.     // TODO Auto-generated method stub
  155.     return null;
  156. }
  157.    
  158. public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  159.         {
  160.               // Starting new intent
  161.             Intent in = new Intent(getApplicationContext(), PreviewInvoice.class);
  162.             in.putExtra("myinvoiceid",invoiceList.get(position).get(TAG_INVOICE_ID));
  163.             in.putExtra("uniquetoken", tokenid); // Actually I can't find your tokenId in HashMAp object
  164.             startActivity(in);
  165.         }
  166.     });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top