我正在尝试使用ArrayList<HashMap<String, String>>
. 我不明白为什么会出现以下错误:
构造函数SimpleAdapter(Main.getResults, ArrayList<HashMap<String,String>>, int, String[])
未定义
public class Main extends Activity {
private static String personURL = "http://api.themoviedb.org/3/search/person?api_key=bb0b6d66c2899aefb4d0863b0d37dc4e&query=";
private static String TAG_CAST = "cast";
private static String TAG_ID = "id";
private static String TAG_TITLE = "title";
String title = null;
JSONArray idOne = null;
JSONArray idTwo = null;
JSONArray firstCast = null;
JSONArray secondCast = null;
EditText searchOne;
EditText searchTwo;
Button findMovies;
List<String> searchOneFilmography = new ArrayList<String>();
List<String> searchTwoFilmography = new ArrayList<String>();
ArrayList<HashMap<String, String>> commonFilmogrpahy = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.totlayout);
searchOne = (EditText) findViewById(R.id.searchOne);
searchTwo = (EditText) findViewById(R.id.searchTwo);
findMovies = (Button) findViewById(R.id.findMovies);
//getting
findMovies.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new getResults().execute();
}
});
}
public class getResults extends AsyncTask<String, Void, ArrayList<HashMap<String, String>> > {
@Override
protected ArrayList<HashMap<String, String>> doInBackground(
String... params) {
// TODO Auto-generated method stub
//get names from each text box
ArrayList<HashMap<String, String>> commonFilms = new ArrayList<HashMap<String, String>>();
ArrayList<HashMap<String, String>> firstFilms = new ArrayList<HashMap<String, String>>();
ArrayList<HashMap<String, String>> secondFilms = new ArrayList<HashMap<String, String>>();
String nameOne = searchOne.getText().toString();
String nameTwo = searchTwo.getText().toString();
nameOne = nameOne.replace(" ", "_");
nameTwo = nameTwo.replace(" ", "_");
String searchOneURL = personURL + nameOne;
String searchTwoURL = personURL + nameTwo;
//Hashmap for ListView
//Create JSON Parser Instanece
JSONParser jParser = new JSONParser();
//getting JSON string from url
JSONObject jsonOne = jParser.getJSONFromUrl(searchOneURL);
JSONObject jsonTwo = jParser.getJSONFromUrl(searchTwoURL);
try {
//Get ID of each person
idOne = jsonOne.getJSONArray(TAG_ID);
idTwo = jsonTwo.getJSONArray(TAG_ID);
String firstID = null;
String secondID = null;
for(int i = 0; i < idOne.length(); i++){
JSONObject iDeeOne = idOne.getJSONObject(i);
//store each json item in variable
firstID = iDeeOne.getString(TAG_ID);
}
for(int i = 0; i < idTwo.length(); i++){
JSONObject iDeeTwo = idTwo.getJSONObject(i);
//store each json item in variable
secondID = iDeeTwo.getString(TAG_ID);
}
String creditURlBase = "http://api.themoviedb.org/3/person";
String firstCreditURL = creditURlBase + firstID;
String secondCreditURL = creditURlBase + secondID;
JSONObject jSon = jParser.getJSONFromUrl(firstCreditURL);
firstCast = jSon.getJSONArray(TAG_CAST);
for(int i = 0; i < firstCast.length(); i++){
JSONObject c = firstCast.getJSONObject(i);
title = c.getString(TAG_TITLE);
//ctreate new hashmap
HashMap<String, String> map = new HashMap<String, String>();
//and node to map
map.put(TAG_TITLE, title);
firstFilms.add(map);
}
JSONObject jSonTwo = jParser.getJSONFromUrl(secondCreditURL);
secondCast = jSonTwo.getJSONArray(TAG_CAST);
for(int i = 0; i < secondCast.length(); i++){
JSONObject c = firstCast.getJSONObject(i);
title = c.getString(TAG_TITLE);
//create hashmap
HashMap<String, String> mapTwo = new HashMap<String, String>();
mapTwo.put(TAG_TITLE, title);
secondFilms.add(mapTwo);
}
if(firstFilms.size() > secondFilms.size()){
for(int i = 0; i < firstFilms.size(); i++){
if(firstFilms.contains(secondFilms.get(i))){
HashMap<String, String> mapThree = new HashMap<String, String>();
mapThree.put(TAG_TITLE, secondFilms.get(i).toString());
commonFilms.add(mapThree);
}
}
}else{
for(int i = 0; i < secondFilms.size(); i++){
if(secondFilms.contains(firstFilms.get(i))){
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_TITLE, firstFilms.get(i).toString());
commonFilms.add(map);
}
}
}
return commonFilms;
}
catch(JSONException e){
Log.e("Error", e.toString());
return null;
}
ListAdapter adapter = new SimpleAdapter(this, commonFilms, R.layout.resultslayout, new String[] {TAG_NAME});
setListAdapter(adapter);
我也试过
ListAdapter adapter = new SimpleAdapter(Main.this, commonFilms, R.layout.resultslayout, new String[] {TAG_NAME});
我仍然只为 Main.this 得到相同的未定义错误。