0

我正在尝试使用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 得到相同的未定义错误。


Android EditText 不起作用,android:imeOptions="actionNext" android:inputType="phone"

我试过android:inputType="phone"了,只有删除键盘Enter才能跳转到Next EditText。不知道android:imeOptions="actionNext"和之间有没有冲突android:inputType="phone"

代码 : AutoCompleteTextViewandroid:imeOptions="actionNext"and android:inputType="phone",但是键盘上的 Enter 不会转到下一个。

         <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:paddingBottom="12dp"
                    android:paddingLeft="13dp"
                    android:paddingTop="12dp"
                    android:src="@drawable/fd_28" />


                <TextView
                    android:id="@+id/texttitle_phone"
                    style="@style/TextviewRentItem"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="30dip" />

                <EditText
                    android:id="@+id/content_phone"
                    style="@style/TextviewRentItemCon3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="50dip"
                    android:layout_toRightOf="@id/texttitle_phone"
                    android:paddingBottom="12dp"
                    android:paddingRight="15dp"
                    android:paddingTop="12dp"
                    android:imeOptions="actionNext"
                    android:singleLine="true" 
                    android:inputType="phone"/>
            </RelativeLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout0_ll"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dip"
            android:background="@drawable/bg_rect_black_filled_white"
            android:orientation="vertical" >

            <!-- the second-->

            <RelativeLayout
                android:id="@+id/linearLayout0"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/img_house"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:paddingBottom="12dp"
                    android:paddingLeft="10dp"
                    android:paddingTop="12dp"
                    android:src="@drawable/fd_29" />

                <TextView
                    android:id="@+id/textview3"
                    style="@style/TextviewRentItem"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="30dip"
                    android:focusable="true"
                    android:text="@string/house" />

                <AutoCompleteTextView
                    android:id="@+id/add_rent_manage_house"
                    style="@style/TextviewRentItemCon3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="50dip"
                    android:layout_toRightOf="@id/textview3"
                    android:dropDownHeight="90dp"
                    android:hint="@string/default_add_rent_house_remind"
                    android:imeOptions="actionNext"
                    android:singleLine="true" />
            </RelativeLayout>
4

1 回答 1

3

你不是错过了一个论点吗?Javadoc forSimpleAdapter说构造函数参数是:

(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

您没有为参数传递任何int[] to参数。

编辑添加:另外,你的getResults类正在扩展AsyncTask,所以它不是Context.

于 2012-09-11T02:40:51.000 回答