当我单击按钮搜索时,我需要在我的列表视图中显示图像和文本,但它在我的setListAdapter(new MobileArrayAdapter(this, PNames,PImages));
.. 中给了我一个错误。我有两个类。当我显示 onformLoad 它工作但现在我需要使用按钮显示它,这里是我的两个类:
B_KZN.setOnClickListener(new View .OnClickListener() {
@Override
public void onClick(View Kv) {
// TODO Auto-generated method stub
JSONObject json = JSONfunctions.getJSONfromURL("http://10.0.2.2/php/p.php");
try{
JSONArray earthquakes = json.getJSONArray("SKZN");
for(int i=0;i<earthquakes.length();i++){
JSONObject e = earthquakes.getJSONObject(i);
String BookName = e.getString("P_City");
PNames.add(BookName);
String BookImg = e.getString("Pname");
PImages.add(BookImg);
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
setListAdapter(new MobileArrayAdapter(this, PNames,PImages));
我的第二堂课:
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] myBookNamelist = null;
private ArrayList<String> MyP = new ArrayList<String>();
private ArrayList<String> myPurl = new ArrayList<String>();
public MobileArrayAdapter(Context context,ArrayList<String> Bname,ArrayList<String> BUrl) {
super(context, R.layout.list_mobile, Bname);
this.context = context;
this.MyP = Bname;
this.myPurl = BUrl;
}
这是我的错误:The constructor MobileArrayAdapter(new View.OnClickListener(){}, ArrayList<String>, ArrayList<String>) is undefined
...它显示了我的红线。