Android onclick不适用于listview

Android onclick不适用于listview,android,listview,onclicklistener,Android,Listview,Onclicklistener,我还在想办法解决这个问题, 丢失了指向android:DegenantFocusability=“BlocksDescents”的帖子,但我似乎仍然无法获得我的列表视图的单击事件 我应该指出,当我点击列表时,背景会变成蓝色,就好像点击被注册了一样,只是代码中什么都没有发生 从我的main.class: package com.whatsonwhere.app; import android.app.ListActivity; import android.content.Broadca

我还在想办法解决这个问题, 丢失了指向android:DegenantFocusability=“BlocksDescents”的帖子,但我似乎仍然无法获得我的
列表视图的单击事件

我应该指出,当我点击列表时,背景会变成蓝色,就好像点击被注册了一样,只是代码中什么都没有发生

从我的main.class:

    package com.whatsonwhere.app;

import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;

import static com.whatsonwhere.app.R.layout.results;


/** Called when the activity is first created. */

public class Home extends ListActivity {

    @Override
    //what happens when the app is launched this is the main proc...
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String[] pages = getResources().getStringArray(R.array.pages_array);

        setListAdapter(new ArrayAdapter<String>(this, results, pages));

        ListView lv = getListView();
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

         @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e("Click", "Click");
                Intent myIntent = null;
                Toast.makeText(getApplicationContext(), "You Pushed a button.",
                        Toast.LENGTH_SHORT).show();
                if(((TextView) view).getText().equals("About")){
                    myIntent = new Intent(view.getContext(), About.class);
                }

                if(((TextView) view).getText().equals("Find events near me")){
                    myIntent = new Intent(view.getContext(), Results.class);
                }

                if(((TextView) view).getText().equals("Somewhere Else")){
                    myIntent = new Intent(view.getContext(), Search.class);
                }

                //if(((TextView) view).getText().equals("Switch to button mode")){
                //myIntent = new Intent(view.getContext(), ButtonPage.class);
                //}

                startActivity(myIntent);
            }
        });




        setContentView(R.layout.activity_home);
        //ok try and find the users location...
        //get Your Current Location
        LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
        MyCurrentLoctionListener locationListener = new MyCurrentLoctionListener();
        //try and get GPS (Fine) Position
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);

        //also get location from network provider - speeds location aquisition up in case user is inside..
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
        //now we have the location wait for the update before it is displayed in onLocationChanged
        TextView textview=(TextView)findViewById(R.id.textView2);
        textview.setText("Searching...");

    }
        public class MyCurrentLoctionListener extends Context implements LocationListener {
        @Override
        public void onLocationChanged(Location location) {
            location.getLatitude();
            location.getLongitude();

            //String myLocation = "Latitude = " + location.getLatitude() + " Longitude = " + location.getLongitude();

            //make a log to see the results
            // Log.e("MY CURRENT LOCATION", myLocation);

            //maybe this is a good place to set the location string..
            //TextView textview = (TextView) findViewById(R.id.textView2);
            //textview.setText(myLocation);
            List<Address> addresses = null;
            try{
                Geocoder geocoder;
                geocoder = new Geocoder(this, Locale.getDefault());
                addresses=(geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1));

            }catch(IOException e){
                e.printStackTrace();
            }

            String address = addresses.get(0).getAddressLine(0);
            String city = addresses.get(0).getAddressLine(1);
            String country = addresses.get(0).getAddressLine(2);

//set the string to our new location

            TextView tv = (TextView) findViewById(R.id.textView2);
            tv.setText(address+"\n"+city+"\n"+country);


        }


            @Override
            public void onStatusChanged(String s, int i, Bundle bundle) {

            }

            @Override
            public void onProviderEnabled(String s) {

            }

            @Override
            public void onProviderDisabled(String s) {

            }


            @Override
            public AssetManager getAssets() {
                return null;
            }

            @Override
            public Resources getResources() {
                return null;
            }

            @Override
            public PackageManager getPackageManager() {
                return null;
            }

            @Override
            public ContentResolver getContentResolver() {
                return null;
            }

            @Override
            public Looper getMainLooper() {
                return null;
            }

            @Override
            public Context getApplicationContext() {
                return null;
            }

            @Override
            public void setTheme(int i) {

            }

            @Override
            public Resources.Theme getTheme() {
                return null;
            }

            @Override
            public ClassLoader getClassLoader() {
                return null;
            }

            @Override
            public String getPackageName() {
                return null;
            }

            @Override
            public ApplicationInfo getApplicationInfo() {
                return null;
            }

            @Override
            public String getPackageResourcePath() {
                return null;
            }

            @Override
            public String getPackageCodePath() {
                return null;
            }

            @Override
            public SharedPreferences getSharedPreferences(String s, int i) {
                return null;
            }

            @Override
            public FileInputStream openFileInput(String s) throws FileNotFoundException {
                return null;
            }

            @Override
            public FileOutputStream openFileOutput(String s, int i) throws FileNotFoundException {
                return null;
            }

            @Override
            public boolean deleteFile(String s) {
                return false;
            }

            @Override
            public File getFileStreamPath(String s) {
                return null;
            }

            @Override
            public File getFilesDir() {
                return null;
            }

            @Override
            public File getExternalFilesDir(String s) {
                return null;
            }

            @Override
            public File[] getExternalFilesDirs(String s) {
                return new File[0];
            }

            @Override
            public File getObbDir() {
                return null;
            }

            @Override
            public File[] getObbDirs() {
                return new File[0];
            }

            @Override
            public File getCacheDir() {
                return null;
            }

            @Override
            public File getExternalCacheDir() {
                return null;
            }

            @Override
            public File[] getExternalCacheDirs() {
                return new File[0];
            }

            @Override
            public String[] fileList() {
                return new String[0];
            }

            @Override
            public File getDir(String s, int i) {
                return null;
            }

            @Override
            public SQLiteDatabase openOrCreateDatabase(String s, int i, SQLiteDatabase.CursorFactory cursorFactory) {
                return null;
            }

            @Override
            public SQLiteDatabase openOrCreateDatabase(String s, int i, SQLiteDatabase.CursorFactory cursorFactory, DatabaseErrorHandler databaseErrorHandler) {
                return null;
            }

            @Override
            public boolean deleteDatabase(String s) {
                return false;
            }

            @Override
            public File getDatabasePath(String s) {
                return null;
            }

            @Override
            public String[] databaseList() {
                return new String[0];
            }

            @Override
            public Drawable getWallpaper() {
                return null;
            }

            @Override
            public Drawable peekWallpaper() {
                return null;
            }

            @Override
            public int getWallpaperDesiredMinimumWidth() {
                return 0;
            }

            @Override
            public int getWallpaperDesiredMinimumHeight() {
                return 0;
            }

            @Override
            public void setWallpaper(Bitmap bitmap) throws IOException {

            }

            @Override
            public void setWallpaper(InputStream inputStream) throws IOException {

            }

            @Override
            public void clearWallpaper() throws IOException {

            }

            @Override
            public void startActivity(Intent intent) {

            }

            @Override
            public void startActivity(Intent intent, Bundle bundle) {

            }

            @Override
            public void startActivities(Intent[] intents) {

            }

            @Override
            public void startActivities(Intent[] intents, Bundle bundle) {

            }

            @Override
            public void startIntentSender(IntentSender intentSender, Intent intent, int i, int i2, int i3) throws IntentSender.SendIntentException {

            }

            @Override
            public void startIntentSender(IntentSender intentSender, Intent intent, int i, int i2, int i3, Bundle bundle) throws IntentSender.SendIntentException {

            }

            @Override
            public void sendBroadcast(Intent intent) {

            }

            @Override
            public void sendBroadcast(Intent intent, String s) {

            }

            @Override
            public void sendOrderedBroadcast(Intent intent, String s) {

            }

            @Override
            public void sendOrderedBroadcast(Intent intent, String s, BroadcastReceiver broadcastReceiver, Handler handler, int i, String s2, Bundle bundle) {

            }

            @Override
            public void sendBroadcastAsUser(Intent intent, UserHandle userHandle) {

            }

            @Override
            public void sendBroadcastAsUser(Intent intent, UserHandle userHandle, String s) {

            }

            @Override
            public void sendOrderedBroadcastAsUser(Intent intent, UserHandle userHandle, String s, BroadcastReceiver broadcastReceiver, Handler handler, int i, String s2, Bundle bundle) {

            }

            @Override
            public void sendStickyBroadcast(Intent intent) {

            }

            @Override
            public void sendStickyOrderedBroadcast(Intent intent, BroadcastReceiver broadcastReceiver, Handler handler, int i, String s, Bundle bundle) {

            }

            @Override
            public void removeStickyBroadcast(Intent intent) {

            }

            @Override
            public void sendStickyBroadcastAsUser(Intent intent, UserHandle userHandle) {

            }

            @Override
            public void sendStickyOrderedBroadcastAsUser(Intent intent, UserHandle userHandle, BroadcastReceiver broadcastReceiver, Handler handler, int i, String s, Bundle bundle) {

            }

            @Override
            public void removeStickyBroadcastAsUser(Intent intent, UserHandle userHandle) {

            }

            @Override
            public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter) {
                return null;
            }

            @Override
            public Intent registerReceiver(BroadcastReceiver broadcastReceiver, IntentFilter intentFilter, String s, Handler handler) {
                return null;
            }

            @Override
            public void unregisterReceiver(BroadcastReceiver broadcastReceiver) {

            }

            @Override
            public ComponentName startService(Intent intent) {
                return null;
            }

            @Override
            public boolean stopService(Intent intent) {
                return false;
            }

            @Override
            public boolean bindService(Intent intent, ServiceConnection serviceConnection, int i) {
                return false;
            }

            @Override
            public void unbindService(ServiceConnection serviceConnection) {

            }

            @Override
            public boolean startInstrumentation(ComponentName componentName, String s, Bundle bundle) {
                return false;
            }

            @Override
            public Object getSystemService(String s) {
                return null;
            }

            @Override
            public int checkPermission(String s, int i, int i2) {
                return 0;
            }

            @Override
            public int checkCallingPermission(String s) {
                return 0;
            }

            @Override
            public int checkCallingOrSelfPermission(String s) {
                return 0;
            }

            @Override
            public void enforcePermission(String s, int i, int i2, String s2) {

            }

            @Override
            public void enforceCallingPermission(String s, String s2) {

            }

            @Override
            public void enforceCallingOrSelfPermission(String s, String s2) {

            }

            @Override
            public void grantUriPermission(String s, Uri uri, int i) {

            }

            @Override
            public void revokeUriPermission(Uri uri, int i) {

            }

            @Override
            public int checkUriPermission(Uri uri, int i, int i2, int i3) {
                return 0;
            }

            @Override
            public int checkCallingUriPermission(Uri uri, int i) {
                return 0;
            }

            @Override
            public int checkCallingOrSelfUriPermission(Uri uri, int i) {
                return 0;
            }

            @Override
            public int checkUriPermission(Uri uri, String s, String s2, int i, int i2, int i3) {
                return 0;
            }

            @Override
            public void enforceUriPermission(Uri uri, int i, int i2, int i3, String s) {

            }

            @Override
            public void enforceCallingUriPermission(Uri uri, int i, String s) {

            }

            @Override
            public void enforceCallingOrSelfUriPermission(Uri uri, int i, String s) {

            }

            @Override
            public void enforceUriPermission(Uri uri, String s, String s2, int i, int i2, int i3, String s3) {

            }

            @Override
            public Context createPackageContext(String s, int i) throws PackageManager.NameNotFoundException {
                return null;
            }

            @Override
            public Context createConfigurationContext(Configuration configuration) {
                return null;
            }

            @Override
            public Context createDisplayContext(Display display) {
                return null;
            }


        }
//The next two are menu options...
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        Toast.makeText(getApplicationContext(), "Not Implemented Yet.",
                Toast.LENGTH_SHORT).show();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
package com.whatsonwhere.app;
导入android.app.ListActivity;
导入android.content.BroadcastReceiver;
导入android.content.ComponentName;
导入android.content.ContentResolver;
导入android.content.Context;
导入android.content.Intent;
导入android.content.IntentFilter;
导入android.content.IntentSender;
导入android.content.ServiceConnection;
导入android.content.SharedReferences;
导入android.content.pm.ApplicationInfo;
导入android.content.pm.PackageManager;
导入android.content.res.AssetManager;
导入android.content.res.Configuration;
导入android.content.res.Resources;
导入android.database.DatabaseErrorHandler;
导入android.database.sqlite.SQLiteDatabase;
导入android.graphics.Bitmap;
导入android.graphics.drawable.drawable;
导入android.location.Address;
导入android.location.Geocoder;
导入android.location.location;
导入android.location.LocationListener;
导入android.location.LocationManager;
导入android.net.Uri;
导入android.os.Bundle;
导入android.os.Handler;
导入android.os.Looper;
导入android.os.UserHandle;
导入android.util.Log;
导入android.view.Display;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.ListView;
导入android.widget.TextView;
导入android.widget.Toast;
导入java.io.File;
导入java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.io.InputStream;
导入java.util.List;
导入java.util.Locale;

导入静态com.whatsonwhere.app.R.layout.results; /**在首次创建活动时调用*/ 公共课家庭活动{ @凌驾 //当应用程序启动时会发生什么这是主程序。。。 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); String[]pages=getResources().getStringArray(R.array.pages\u数组); setListAdapter(新的ArrayAdapter(此、结果、页面)); ListView lv=getListView(); lv.setOnItemClickListener(新的AdapterView.OnItemClickListener(){ @凌驾 public void onItemClick(AdapterView父对象、视图、整型位置、长id){ Log.e(“点击”、“点击”); Intent myIntent=null; Toast.makeText(getApplicationContext(),“您按下了一个按钮。”, 吐司。长度(短)。show(); if(((TextView)view.getText().equals(“About”)){ myIntent=newintent(view.getContext(),About.class); } if(((TextView)view.getText().equals(“查找我附近的事件”)){ myIntent=newintent(view.getContext(),Results.class); } if(((TextView)view.getText().equals(“其他地方”)){ myIntent=newintent(view.getContext(),Search.class); } //if(((TextView)view.getText().equals(“切换到按钮模式”)){ //myIntent=新意图(view.getContext(),ButtonPage.class); //} 星触觉(myIntent); } }); setContentView(R.layout.activity_home); //好的,请尝试查找用户位置。。。 //获取当前位置 LocationManager LocationManager=(LocationManager)getSystemService(Context.LOCATION\u服务); MyCurrentLocationListener locationListener=新的MyCurrentLocationListener(); //尝试获取GPS(精细)位置 locationManager.RequestLocationUpdate(locationManager.GPS\提供程序,0,0,locationListener); //还可以从网络提供商处获取位置信息-加快位置获取速度,以防用户在其中。。 locationManager.RequestLocationUpdate(locationManager.NETWORK\u提供程序,0,0,locationListener); //现在,我们让位置在onLocationChanged中显示之前等待更新 TextView TextView=(TextView)findViewById(R.id.textView2); setText(“搜索…”); } 公共类MyCurrentLocationListener扩展上下文实现LocationListener{ @凌驾 已更改位置上的公共无效(位置){ location.getLatitude(); location.getLongitude(); //字符串myLocation=“Latitude=“+location.getLatitude()+”Longitude=“+location.getLongitude()”; //制作日志以查看结果 //Log.e(“我的当前位置”,myLocation); //也许这是设置位置字符串的好地方。。 //TextView TextView=(TextView)findViewById(R.id.textView2); //textview.setText(myLocation); 列表地址=空; 试一试{ 地理编码器; geocoder=新的geocoder(这个,Locale.getDefault()); 地址=(geocoder.getFromLocation(location.getLatitude(),location.getLatitude(),1)); }捕获(IOE异常){ e、 printStackTrace(); } 字符串地址=地址.get(0).getAddressLine(0); 字符串city=addresses.get(0).getAddressLine(1); 字符串country=addresses.get(0).getAddressLine(2); //将字符串设置为我们的新位置 TextView tv=(TextView)findViewById(R.id.textView2); tv.setText(地址+“\n”+城市+“\n”+国家); } @凌驾 聚氨基甲酸酯
    <?xml version="1.0" encoding="utf-8"?>

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:textSize="18sp" >
    </TextView>
   <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#ffffff">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"

        android:src="@drawable/logo" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/l_location"
        android:id="@+id/textView"
        android:layout_alignParentTop="true"

        android:layout_toRightOf="@+id/imageView"
        android:layout_alignEnd="@+id/textView2"
        android:singleLine="false" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium"
        android:text="@string/l_mylocation"
        android:id="@+id/textView2"

        android:layout_below="@+id/textView"
        android:layout_toRightOf="@+id/imageView"
        android:layout_alignParentEnd="true" />
    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_below="@+id/imageView" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="10dp"
android:textSize="18sp" >
</TextView>