我如何从一个aSyncTask类返回一个ArrayList对象和一个String.
aSyncTask使用Jsoup来检索表中的3个元素,这些元素放入一个新的Employee类中,然后作为一个arrayList返回给MainActivity,但我希望它还返回该特定表的String.
主要活动
public voID onbuttonClick() new GetEmployee() { @OverrIDe protected voID onPostExecute(ArrayList<Employee> List) { Intent intent = new Intent(getApplicationContext(), EmployeeActivity.class); intent.putParcelableArrayListExtra("empClass", List); //i want to also pass the Title of the Employee table aswell as the List, //after running the aSyncTask startActivity(intent); } }.execute();
getEmployee的
public Employee empObj;@OverrIDeprotected ArrayList<Employee> doInBackground(String... params) { ArrayList<Employee> emp = new ArrayList<Employee>(); String Title; try { //get employee details from table using Jsoup //get employee table Title using Jsoup empObj = new Emp(...); emp.add(empObj); return emp; } catch (IOException e) { e.printstacktrace(); } return emp;
我如何从这里返回一个String以及一个Employee的ArrayList
解决方法:
另一种方法可以如下……
在您的GetEmployee类中添加以下行:
abstract class GetEmployee{// your declarationString Title; //my return string@OverrIDeprotected ArrayList<Employee> doInBackground(String... params){ ArrayList<Employee> emp = new ArrayList<Employee>(); String Title; try { //get employee details from table using Jsoup //get employee table Title using Jsoup empObj = new Emp(...); bus.add(empObj); title="myTitle" //fetch some Title value here...2 return emp; } catch (IOException e) { e.printstacktrace(); } return emp;}@OverrIDeprotected voID onPostExecute(ArrayList<Employee> List) { myPostExecute(List,Title);}public abstract voID myPostExecute(ArrayList<Employee> emp,String Title);}
现在在您的MainActivity中:
public voID onbuttonClick()new GetEmployee() { @OverrIDe protected voID myPostExecute(ArrayList<Employee> List,String Title) { Intent intent = new Intent(getApplicationContext(), EmployeeActivity.class); intent.putParcelableArrayListExtra("busClass", List); intent.putString("Title",Title);//this is your Title startActivity(intent); }}.execute();
总结 以上是内存溢出为你收集整理的java – 返回一个ArrayList和String asyncTask全部内容,希望文章能够帮你解决java – 返回一个ArrayList和String asyncTask所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)