【发布时间】:2015-07-01 04:27:00
【问题描述】:
在下面的代码中,我在另一个类 Use 的帮助下保存了三个值 fun_id、fun_logo、fun_req。在代码中返回了一个数组列表,现在我想检索 fun_id、fun_logo、fun_req。我想将 fun_logo 添加到 imagearray。我想知道如何使用 Class Use 来检索数据。我目前正在学习所以只是关于 android 的小想法。
ArrayList<Use> stringArrayList = null;
ArrayList<Use> res = null;
ArrayList<String> linklist = null;
String getdetailsurl;
String link [];
String[] ar;
Use[] getalldet;
public String imagearray[];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Getdetailsfromweb().execute();
list=(ListView)findViewById(R.id.listView1);
// adapter=new myadpter(this, imagearray);
list.setAdapter(adapter);
}
public class Getdetailsfromweb extends AsyncTask<String,Void,String>
{
String result = "";
@Override
protected String doInBackground(String... params) {
getdetailsurl=Webcall.getdet();
if(getdetailsurl!=null)
{
result = "Success";
}
else
{
result = "Failure";
}
return result;
}
@Override
protected void onPostExecute(String result) {
res = new ArrayList<Use>();
try {
if (result.contentEquals("Success"))
{
res=passdetails();
System.out.println("lsize is " + res.size());
for(int i=0;i<res.size();i++)
{
// To retreive value what should i do here
imagearray[i]=obj.funlogo;
System.out.println("logo is " + imagearray[i]);
}
}
else
{
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
public ArrayList<Use> passdetails()
{
JSONArray array = null;
stringArrayList = new ArrayList<Use>();
linklist= new ArrayList<String>();
Use usee;
try {
array = new JSONArray(getdetailsurl);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(int i = 0;i <array.length() ;i++ )
{
String fun_id= null;
String fun_logo= null;
String fun_req = null;
try {
fun_id = array.getJSONObject(i).getString("up_id");
System.out.println("up_id is " + fun_id);
fun_logo=array.getJSONObject(i).getString("logo");
System.out.println("logo is " + fun_logo);
fun_req=array.getJSONObject(i).getString("requirements");
System.out.println("req is " + fun_req);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
usee=new Use();
usee.funid=fun_id;
System.out.println("fun is " + usee.funid);
usee.funlogo=fun_logo;
System.out.println("fun is " + usee.funlogo);
usee.funreq=fun_req;
System.out.println("fun is " + usee.funreq);
linklist.add(fun_logo);
stringArrayList.add(usee);
}
return stringArrayList;
}
}
使用.java
public class Use {
public static String funid;
public String funlogo;
public String funreq;
}
【问题讨论】:
-
将变量 String imageUrl 添加到你的类中使用并使用它
-
你需要一本 C++/JAVA 书籍来学习 OOPS 基础知识!
-
@PareshMayani 哈哈..看看我的代码,你是这么认为的..ya ...关于 OOPS 概念的模糊概念....以某种方式运行代码并获得输出...
-
@HariSankar 我的观察表明,因为您已经全局声明了所有变量,这不是声明和使用变量的优化方式。范围应该是有限的。
-
@PareshMayani 正在查看您在某个博客上找到的示例以下载图像并在列表视图中显示..
标签: android class arraylist android-asynctask