0

私のAndroidプロジェクトでは、を作成し、ListViewそれonClickListenerに追加しましたが、プロジェクトの実行中にListView、クリックに対して応答しません。

コード

public class MyDayListActivity extends ListActivity {

    // JSON Node names
                private static final String TAG_RESULTS = "results";
                private static final String TAG_ID = "id";
                private static final String TAG_NAME = "name";
                private static final String TAG_RATING = "rating";
                private static final String TAG_REFERENCE = "reference";
                private static final String TAG_ICON = "icon";

    // contacts JSONArray
    JSONArray result = null;
    String url,reference;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         Intent in = getIntent();
         String location = in.getStringExtra("TAG_LOCATION");
         String type = in.getStringExtra("TAG_TYPE");

        // url to make request
        url = "https://maps.googleapis.com/maps/api/place/textsearch/json?query="+type+"+in+"+location+"&sensor=true&key=AIzaSyD38pak_katUfSR92WE2_O2b9y0JSp5htA";
    new LoadData().execute();

    }
class LoadData extends AsyncTask<String, String, String>
    { 
    // Hashmap for ListView
    ArrayList<HashMap<String, String>> contactList = new ArrayList<HashMap<String, String>>();
    protected String doInBackground(String... args) {

    // Creating JSON Parser instance
        JSONParser jParser = new JSONParser();

    // getting JSON string from URL
        JSONObject json = jParser.getJSONFromUrl(url);


        try {
            // Getting Array of Results
            result = json.getJSONArray(TAG_RESULTS);

            // looping through All Contacts
            for(int i = 0; i < result.length(); i++){

                JSONObject c = result.getJSONObject(i);

                // Storing each json item in variable
                String id = c.getString(TAG_ID);
                String name = c.getString(TAG_NAME);
                String icon = c.getString(TAG_ICON);
                reference  = c.getString(TAG_REFERENCE);
                String rating = c.getString(TAG_RATING);


                // creating new HashMap
                HashMap<String, String> map2 = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map2.put(TAG_ID, id);
                map2.put(TAG_NAME, name);
                map2.put(TAG_ICON, icon);
                map2.put(TAG_RATING, rating);
                map2.put(TAG_REFERENCE, reference);

                // adding HashList to ArrayList
                contactList.add(map2);

                }
        } 
        catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
            }    
        protected void onPostExecute(String file_url) {


         // Updating parsed JSON data into ListView
        ListAdapter adapter1 = new SimpleAdapter(MyDayListActivity.this, contactList,R.layout.listview_item_row,
                new String[] {TAG_NAME}, new int[] {
                        R.id.txtTitle});

        setListAdapter(adapter1);

        // selecting single ListView item

            // Launching new screen on Selecting Single ListItem
        ListView lv1 = getListView(); 

         lv1.setOnItemClickListener(new OnItemClickListener() 
            {

                    public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                // Starting new intent
                Intent in = new Intent(getApplicationContext(), ProfileViewActivity.class);
                in.putExtra(TAG_REFERENCE, reference);
                startActivity(in);

            }
        });
        }

}
}
4

1 に答える 1

2

getListView()。setOnItemLongClickListener(this); public boolean onItemLongClick(final AdapterView myadapter、View arg1、final int arg2、long arg3){

falseを返します。}

于 2012-10-23T01:02:34.603 に答える