2012-10-15 59 views
1
public class circularlistparsing extends ActivityGroup { 

    public int currentPage = 1; 
    public ListView lisView1; 
    static final String KEY_ITEM = "docdetails"; 
    static final String KEY_ITEM2 = "info"; 
    static final String KEY_NAME1 = ""; 
    static final String KEY_NAME = "heading"; 
    static final String KEY_DATE = "date"; 
    public Button btnNext; 
    public Button btnPre; 
    public static String url = "http://dev.taxmann.com/TaxmannService/TaxmannService.asmx/GetCircularList"; 
    TextView txtreord; 
    TextView totalpage; 
    TextView pagenumber; 
    ProgressDialog dialog; 
    TextView title; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     txtreord = (TextView) findViewById(R.id.recored); 
     totalpage = (TextView) findViewById(R.id.totalpage); 
     pagenumber = (TextView) findViewById(R.id.pagenumber); 
     title = (TextView) findViewById(R.id.title); 

     title.setText("Cirrcular"); 
     // listView1 
     lisView1 = (ListView) findViewById(R.id.listView1); 

     // Next 
     btnNext = (Button) findViewById(R.id.btnNext); 
     // Perform action on click 
     btnNext.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       currentPage = currentPage + 1; 

       // new YourTask().execute(); 
       ShowData(); 
       pagenumber.setText("Of" + currentPage + "]"); 
      } 
     }); 

     // Previous 
     btnPre = (Button) findViewById(R.id.btnPre); 
     // Perform action on click 
     btnPre.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       currentPage = currentPage - 1; 

       // new YourTask().execute(); 
       ShowData(); 
       pagenumber.setText("Of" + currentPage + "]"); 
      } 
     }); 


     ShowData(); 
    } 

    public void ShowData() { 
     XMLParser parser = new XMLParser(); 
     String xml = parser.getXmlFromUrl(url); // getting XML 

     Document doc = parser.getDomElement(xml); // getting DOM element 

     NodeList nl = doc.getElementsByTagName(KEY_ITEM); 

     NodeList n2 = doc.getElementsByTagName(KEY_ITEM2); 

     int displayPerPage = 10; // Per Page 
     int TotalRows = nl.getLength(); 

     txtreord.setText(TotalRows + "Records|"); // number of records 

     int indexRowStart = ((displayPerPage * currentPage) - displayPerPage); 
     int TotalPage = 0; 
     if (TotalRows <= displayPerPage) { 
      TotalPage = 1; 
     } else if ((TotalRows % displayPerPage) == 0) { 
      TotalPage = (TotalRows/displayPerPage); 
     } else { 
      TotalPage = (TotalRows/displayPerPage) + 1; // 7 
      TotalPage = (int) TotalPage; // 7 
     } 

     totalpage.setText("Page[" + TotalPage); 

     int indexRowEnd = displayPerPage * currentPage; // 5 
     if (indexRowEnd > TotalRows) { 
      indexRowEnd = TotalRows; 
     } 

     // Disabled Button Next 
     if (currentPage >= TotalPage) { 
      btnNext.setEnabled(false); 
     } else { 
      btnNext.setEnabled(true); 
     } 

     // Disabled Button Previos 
     if (currentPage <= 1) { 
      btnPre.setEnabled(false); 
     } else { 
      btnPre.setEnabled(true); 
     } 

     // Load Data from Index 
     int RowID = 1; 
     ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); 
     HashMap<String, String> map; 

     // RowID 
     if (currentPage > 1) { 
      RowID = (displayPerPage * (currentPage - 1)) + 1; 
     } 

     for (int i = indexRowStart; i < indexRowEnd; i++) { 
      Element e = (Element) nl.item(i); 

      Element e2 = (Element) n2.item(i); 

      String date = e2.getAttribute(KEY_DATE); 
      // adding each child node to HashMap key => value 

      map = new HashMap<String, String>(); 
      map.put("RowID", String.valueOf(RowID)); 

      map.put(KEY_DATE, date); 



      String mytime = date; 
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmdd"); 
      Date myDate = null; 
      try { 
       myDate = dateFormat.parse(mytime); 

      } catch (ParseException t) { 
       t.printStackTrace(); 
      } catch (java.text.ParseException t) { 
       // TODO Auto-generated catch block 
       t.printStackTrace(); 
      } 

      SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd"); 
      String finalDate = timeFormat.format(myDate); 

      // System.out.println("rrrrrrrrrrrrr"+finalDate); 

      String Heading = parser.getValue(e, KEY_NAME); 

      int a = Heading.indexOf("|"); 
      String beforeSubString = Heading.substring(0, a); 
      String afterSubString = Heading.substring(a, Heading.length()) 
        .replace("|", "") + "[" + finalDate + "]"; 
      // String 
      // final1="<b>"+beforeSubString+"<b>"+"|"+afterSubString.replace("|", 
      // "|\n") 
      // .replace("|", ""); 
      // String k=Html.fromHtml(final1).toString(); 
      // 
      // Html.fromHtml(final1); 

      map.put(KEY_NAME, beforeSubString); 
      map.put(KEY_NAME1, afterSubString); 

      // adding HashList to ArrayList 
      menuItems.add(map); 

      RowID = RowID + 1; 

     } 

     SimpleAdapter sAdap; 
     sAdap = new SimpleAdapter(circularlistparsing.this, menuItems, 
       R.layout.list_item, 
       new String[] { "RowID", KEY_NAME1, KEY_NAME }, new int[] { 
         R.id.ColRowID, R.id.ColName, R.id.textView1 }); 
     lisView1.setAdapter(sAdap); 

     lisView1.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
        long arg3) { 
       // TODO Auto-generated method stub 

       Intent i = new Intent(circularlistparsing.this, detail.class); 
       // sending data to new activity 
       // i.putExtra("product", product); 
       startActivity(i); 

      } 
     }); 

    } 
} 

後發現沒有數據。這是我的源代碼我要顯示的消息,如果沒有在某些情況下,解析堂妹後發現數據沒有內容,請參閱我的代碼,並請告訴我如何我會把代碼,以便它顯示的messge如果數據沒有找到合適的,如果現在的數據是不是有那麼應用程序變得接近。如何顯示消息如果解析

回答

0

您可以返回數據或null在您的方法,並根據檢查,如果您得到null調用該方法。如果是null只顯示沒有數據

0

,您可以檢查intRowStartintRowEnd相同或不

如果相同,則不會顯示數據和

顯示dialog with no data發現

,而不是設置適配器..

當OK按鈕使用點擊然後再回去取數據....

+0

確定我在做,以告訴你它的工作或沒有 – user1719722

+0

沒有它實際上不是 – user1719722

+0

工作沒有ü得到它的差異?? 或任何錯誤..? – SilentKiller

0

您可以檢查的ArrayList(的菜單項)爲空。

if(menuItems.isEmpty()) 
{ 
    No record found. 
} 
else 
{ 

    set the listAdapter. 
} 
+0

不工作不應用此邏輯變爲接近時,數據沒有找到... – user1719722

+0

(的菜單項== NULL) –

+0

沒有靜止UR邏輯並不加工 – user1719722