如果解析后未找到数据,如何显示消息 公共类循环搜索扩展了ActivityGroup{ 公共int currentPage=1; 公共列表视图lisView1; 静态最终字符串键\u ITEM=“docdetails”; 静态最终字符串键\u ITEM2=“info”; 静态最终字符串键_NAME1=“”; 静态最终字符串键\u NAME=“heading”; 静态最终字符串键\u DATE=“DATE”; 公共按钮btnNext; 公共按钮btnPre; 公共静态字符串url=”http://dev.taxmann.com/TaxmannService/TaxmannService.asmx/GetCircularList"; TextView-txtreord; 文本浏览网页; 文本视图页码; 进程对话; 文本视图标题; @凌驾 创建时的公共void(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); 标题:setText(“环形”); //列表视图1 lisView1=(ListView)findViewById(R.id.listView1); //下一个 btnNext=(按钮)findViewById(R.id.btnNext); //单击后执行操作 btnNext.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ currentPage=currentPage+1; //新建YourTask().execute(); ShowData(); pagenumber.setText(“Of”+currentPage+“]”); } }); //先前的 btnPre=(按钮)findViewById(R.id.btnPre); //单击后执行操作 btnPre.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ currentPage=currentPage-1; //新建YourTask().execute(); ShowData(); pagenumber.setText(“Of”+currentPage+“]”); } }); ShowData(); } 公共void ShowData(){ XMLParser=新的XMLParser(); 字符串xml=parser.getXmlFromUrl(url);//获取xml Document doc=parser.getDomeElement(xml);//获取DOM元素 NodeList nl=doc.getElementsByTagName(键项); NodeList n2=doc.getElementsByTagName(KEY_ITEM2); int displayPerPage=10;//每页 int TotalRows=nl.getLength(); txtreord.setText(TotalRows+“Records |”);//记录数 int indexRowStart=((显示每页*当前页)-显示每页); int TotalPage=0; if(总计行总计行){ indexRowEnd=总行数; } //禁用按钮下一步 如果(当前页面>=TotalPage){ btnNext.setEnabled(false); }否则{ btnNext.setEnabled(真); } //禁用按钮Previos 如果(当前第1页){ RowID=(显示每页*(当前页-1))+1; } 对于(int i=indexRowStart;ivalue map=新的HashMap(); map.put(“RowID”,String.valueOf(RowID)); 地图放置(钥匙日期,日期); 字符串mytime=日期; SimpleDataFormat dateFormat=新的SimpleDataFormat(“yyyymmdd”); Date myDate=null; 试一试{ myDate=dateFormat.parse(mytime); }捕获(解析异常){ t、 printStackTrace(); }catch(java.text.parset){ //TODO自动生成的捕捉块 t、 printStackTrace(); } SimpleDataFormat timeFormat=新SimpleDataFormat(“yyyy-MM-dd”); 字符串finalDate=timeFormat.format(myDate); //系统输出打印项次(“RRRRRRR”+最终日期); String Heading=parser.getValue(e,KEY\u NAME); int a=标题.indexOf(“|”); 字符串beforeSubString=标题.substring(0,a); String afterSubString=Heading.substring(a,Heading.length()) .替换(“|”和“)+”[“+最终日期+”]; //串 //final1=“”+子字符串前+“+”|“+子字符串后。替换(“|”, //“|\n”) //.替换(“|”和“); //字符串k=Html.fromHtml(final1.toString(); // //Html.fromHtml(final1); map.put(关键字名称,在子字符串之前); 映射放置(键名称1,后子串); //将哈希列表添加到ArrayList menuItems.add(地图); RowID=RowID+1; } SimpleDapter-sAdap; sAdap=新的SimpleAdapter(循环搜索)。此,菜单项, R.layout.list_项目, 新字符串[]{“RowID”,键\名称1,键\名称},新int[]{ R.id.ColRowID、R.id.ColName、R.id.textView1}); lisView1.setAdapter(sAdap); lisView1.setOnItemClickListener(新的OnItemClickListener(){ @凌驾 公共链接(AdapterView arg0、视图arg1、内部arg2、, 长arg3){ //TODO自动生成的方法存根 意图i=新意图(circularlistparsing.this,detail.class); //向新活动发送数据 //i.putExtra(“产品”,产品); 星触觉(i); } }); } }
这是我的源代码,如果解析后没有找到数据,我想显示消息,因为在某些情况下没有找到数据,请查看我的代码,并告诉我如何放置代码,以便显示消息如果现在没有找到数据,如果没有数据,则应用程序将关闭。您可以返回数据或如果解析后未找到数据,如何显示消息 公共类循环搜索扩展了ActivityGroup{ 公共int currentPage=1; 公共列表视图lisView1; 静态最终字符串键\u ITEM=“docdetails”; 静态最终字符串键\u ITEM2=“info”; 静态最终字符串键_NAME1=“”; 静态最终字符串键\u NAME=“heading”; 静态最终字符串键\u DATE=“DATE”; 公共按钮btnNext; 公共按钮btnPre; 公共静态字符串url=”http://dev.taxmann.com/TaxmannService/TaxmannService.asmx/GetCircularList"; TextView-txtreord; 文本浏览网页; 文本视图页码; 进程对话; 文本视图标题; @凌驾 创建时的公共void(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); 标题:setText(“环形”); //列表视图1 lisView1=(ListView)findViewById(R.id.listView1); //下一个 btnNext=(按钮)findViewById(R.id.btnNext); //单击后执行操作 btnNext.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ currentPage=currentPage+1; //新建YourTask().execute(); ShowData(); pagenumber.setText(“Of”+currentPage+“]”); } }); //先前的 btnPre=(按钮)findViewById(R.id.btnPre); //单击后执行操作 btnPre.setOnClickListener(新视图.OnClickListener(){ 公共void onClick(视图v){ currentPage=currentPage-1; //新建YourTask().execute(); ShowData(); pagenumber.setText(“Of”+currentPage+“]”); } }); ShowData(); } 公共void ShowData(){ XMLParser=新的XMLParser(); 字符串xml=parser.getXmlFromUrl(url);//获取xml Document doc=parser.getDomeElement(xml);//获取DOM元素 NodeList nl=doc.getElementsByTagName(键项); NodeList n2=doc.getElementsByTagName(KEY_ITEM2); int displayPerPage=10;//每页 int TotalRows=nl.getLength(); txtreord.setText(TotalRows+“Records |”);//记录数 int indexRowStart=((显示每页*当前页)-显示每页); int TotalPage=0; if(总计行总计行){ indexRowEnd=总行数; } //禁用按钮下一步 如果(当前页面>=TotalPage){ btnNext.setEnabled(false); }否则{ btnNext.setEnabled(真); } //禁用按钮Previos 如果(当前第1页){ RowID=(显示每页*(当前页-1))+1; } 对于(int i=indexRowStart;ivalue map=新的HashMap(); map.put(“RowID”,String.valueOf(RowID)); 地图放置(钥匙日期,日期); 字符串mytime=日期; SimpleDataFormat dateFormat=新的SimpleDataFormat(“yyyymmdd”); Date myDate=null; 试一试{ myDate=dateFormat.parse(mytime); }捕获(解析异常){ t、 printStackTrace(); }catch(java.text.parset){ //TODO自动生成的捕捉块 t、 printStackTrace(); } SimpleDataFormat timeFormat=新SimpleDataFormat(“yyyy-MM-dd”); 字符串finalDate=timeFormat.format(myDate); //系统输出打印项次(“RRRRRRR”+最终日期); String Heading=parser.getValue(e,KEY\u NAME); int a=标题.indexOf(“|”); 字符串beforeSubString=标题.substring(0,a); String afterSubString=Heading.substring(a,Heading.length()) .替换(“|”和“)+”[“+最终日期+”]; //串 //final1=“”+子字符串前+“+”|“+子字符串后。替换(“|”, //“|\n”) //.替换(“|”和“); //字符串k=Html.fromHtml(final1.toString(); // //Html.fromHtml(final1); map.put(关键字名称,在子字符串之前); 映射放置(键名称1,后子串); //将哈希列表添加到ArrayList menuItems.add(地图); RowID=RowID+1; } SimpleDapter-sAdap; sAdap=新的SimpleAdapter(循环搜索)。此,菜单项, R.layout.list_项目, 新字符串[]{“RowID”,键\名称1,键\名称},新int[]{ R.id.ColRowID、R.id.ColName、R.id.textView1}); lisView1.setAdapter(sAdap); lisView1.setOnItemClickListener(新的OnItemClickListener(){ @凌驾 公共链接(AdapterView arg0、视图arg1、内部arg2、, 长arg3){ //TODO自动生成的方法存根 意图i=新意图(circularlistparsing.this,detail.class); //向新活动发送数据 //i.putExtra(“产品”,产品); 星触觉(i); } }); } },java,android,Java,Android,这是我的源代码,如果解析后没有找到数据,我想显示消息,因为在某些情况下没有找到数据,请查看我的代码,并告诉我如何放置代码,以便显示消息如果现在没有找到数据,如果没有数据,则应用程序将关闭。您可以返回数据或null
nullpublic 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);
}
});
}
}
if(menuItems.isEmpty())
{
No record found.
}
else
{
set the listAdapter.
}