Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
androids listView';s setOnItemClickListener仅在不更新数据集时工作。更新后,它停止_Android_Android Listview - Fatal编程技术网

androids listView';s setOnItemClickListener仅在不更新数据集时工作。更新后,它停止

androids listView';s setOnItemClickListener仅在不更新数据集时工作。更新后,它停止,android,android-listview,Android,Android Listview,我创建了wifi频道的ListView,它工作正常,onResume()调用AsyncTask更新列表,但更新后,单击侦听器停止工作,即使我再次尝试设置它。这是我的密码: package co.uk.company.application.ui.wifi; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bu

我创建了wifi频道的ListView,它工作正常,onResume()调用AsyncTask更新列表,但更新后,单击侦听器停止工作,即使我再次尝试设置它。这是我的密码:

package co.uk.company.application.ui.wifi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import co.uk.company.application.R;
import co.uk.company.application.injected.ApplicationGlobalState;
import co.uk.company.application.ui.companyActivity;
import co.uk.company.application.ui.dialog.YesNoAlertDialogCreator;
import co.uk.company.sources.telnet.WifiTelnetClass;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.Vector;
import roboguice.inject.InjectView;

public class WifiAPsActivity extends companyActivity{
    @Inject private ApplicationGlobalState applicationGlobalState;
    @InjectView(R.id.wifi_networks_list) private ListView listView1;
    private WifiChannels wifiChannels;
    private WifiChannel channelSelected;
    private ArrayList<WifiChannel> data;
    private ArrayList<WifiChannel> dataold;
    private Vector <WifiChannel> vect;
    private WifiAPsAdapter adapter;
    private RealtimeUpdateScreen realtimeUpdateScreen;
    private AdapterView.OnItemClickListener listener;
    @Override
    public void onCreate(Bundle savedInstanceState){
        Log.w("","onCreate(...) start");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wifi_networks);
        listener= new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
                arg0.showContextMenuForChild(arg1);
                //if(adapter.getItem(arg2).toString().endsWith(".txt"))
                Toast.makeText(getApplicationContext(),getString(R.string.loading), Toast.LENGTH_LONG).show();                
            }
        };
        dataold= new ArrayList<WifiChannel>();
        data =new ArrayList<WifiChannel>();
        wifiChannels=applicationGlobalState.wifiCurrentChannels;
        if (wifiChannels != null)
                for(WifiChannel chn : wifiChannels.getChannels()){
                        dataold.add(chn);
                        data.add(chn);
                }
        wifiChannels=applicationGlobalState.wifiCurrentChannels5GHz;
        if (wifiChannels != null)
                for(WifiChannel chn : wifiChannels.getChannels()){
                        dataold.add(chn);
                        data.add(chn);
                }
        adapter = new WifiAPsAdapter(this,R.layout.wifi_networks_item_row, data);
        listView1.setAdapter(adapter);
        listView1.setItemsCanFocus(false);
        registerForContextMenu(listView1);
        listView1.setOnItemClickListener(listener);
        Log.w("","onCreate(...) finish");
    }

    @Override
    public void onResume(){
        Log.w("","onResume() start");
        super.onResume();
        //realtimeUpdateScreen = new RealtimeUpdateScreen();
        //realtimeUpdateScreen.execute(new Object());
        Log.w("","onResume() finish");
    }

    @Override
    public void onPause(){
        super.onPause();
        realtimeUpdateScreen.cancel(true);
        realtimeUpdateScreen = null;
        Log.w("","onPause() finish");
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo){
        Log.w("","onCreateContextMenu");
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        // menu.setHeaderTitle(fileNames.get(info.position));
        channelSelected = data.get(info.position);
        menu.add(Menu.NONE, 0, 0, "Connect");
        menu.add(Menu.NONE, 1, 1, "Disconnect");
        menu.add(Menu.NONE, 2, 2, "Do nothing");
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        Log.w("","onContextItemSelected");
        int menuItemIndex = item.getItemId();
        //final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        switch (menuItemIndex){
        case 0:
            final AlertDialog.Builder alert = new AlertDialog.Builder(this);

                LayoutInflater li = LayoutInflater.from(this);
                View promptsView = li.inflate(R.layout.dialog_with_text_fields, null);
                alert.setView(promptsView);
                final TextView SSIDfield = (TextView) promptsView.findViewById(R.id.ssid_field);
                final EditText input2 = (EditText) promptsView.findViewById(R.id.password_field);
                SSIDfield.setText(channelSelected.getName());
//                final Button okButton = (Button)   promptsView.findViewById(R.id.wifi_button_yes);
//                final Button cancelButton =(Button)promptsView.findViewById(R.id.wifi_button_no);
//                okButton.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View arg0) {
//
//                    }
//                });
//
//                cancelButton.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View arg0) {
//                       // alert.
//                    }
//                });

                alert.setPositiveButton("OKK",
                      new DialogInterface.OnClickListener(){
                        public void onClick(DialogInterface dialog,int id) {
                            String SSID = channelSelected.getName();
                            String PASSWORD = input2.getText().toString().trim();
                            if(WifiTelnetClass.getInstance().connect(SSID, PASSWORD))
                                Toast.makeText(getApplicationContext(), SSID+" Connected", Toast.LENGTH_SHORT).show();
                            else Toast.makeText(getApplicationContext(), "Not Connected!", Toast.LENGTH_SHORT).show();
                        }
                      });

                alert.setNegativeButton("CCancel",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            dialog.cancel();
                        }
                    });
                alert.show();
            break;
        case 1:
            YesNoAlertDialogCreator.create(this, "Are You Sure?",
            getString(R.string.sure_delete_result), new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int whichButton) {
                    Toast.makeText(getApplicationContext(),"Disconnecting!!", Toast.LENGTH_LONG).show();
                    if(WifiTelnetClass.getInstance().disconnect())
                        Toast.makeText(getApplicationContext(), " Disconnected", Toast.LENGTH_SHORT).show();
                    else Toast.makeText(getApplicationContext(), "Not Disconnected!", Toast.LENGTH_SHORT).show();
                }
            }).show();           
            Toast.makeText(getApplicationContext(),"Nothing!!!", Toast.LENGTH_LONG).show();
            break;
        case 2:
            YesNoAlertDialogCreator.create(this, "Password please!!!",
            getString(R.string.sure_delete_result), new DialogInterface.OnClickListener(){
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            }).show();
            Toast.makeText(getApplicationContext(),"It!", Toast.LENGTH_LONG).show(); 
            break;   
        }
        return true;
    }

    class RealtimeUpdateScreen extends AsyncTask{
        @Override
            protected void onPreExecute(){
                try{

                    Thread.sleep(50L);
                }catch(Exception e){}
        }
        @Override
        protected Object doInBackground(Object... arg0){
            while(!isCancelled()){
                try{
                    if(wifiChannels!=applicationGlobalState.wifiCurrentChannels)
                        publishProgress(arg0);
                    try{Thread.sleep(50);}catch(Exception e){}
                }catch(Exception e){Log.e("","",e);}
            }
            return null;
        }
        protected void onProgressUpdate(Object...objects ){
            try{
                for(WifiChannel chn_ : dataold){
                    adapter.remove(chn_);
                }
            }catch(Exception e){Log.e("","",e);}
            try{
                dataold = new ArrayList<WifiChannel>();
                //adapter.notifyDataSetChanged();
                vect=applicationGlobalState.wifiCurrentChannels5GHz.getChannels();
                for(WifiChannel chn : vect){
                    dataold.add(chn);
                    adapter.add(chn);
                }                
                vect=applicationGlobalState.wifiCurrentChannels.getChannels();
                for(WifiChannel chn : vect){
                    dataold.add(chn);
                    adapter.add(chn);
                }
                adapter.notifyDataSetChanged();
            }catch(Exception e){Log.e("","",e);}
        }
    }
}
package co.uk.company.application.ui.wifi;
导入android.app.AlertDialog;
导入android.content.DialogInterface;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.ContextMenu;
导入android.view.LayoutInflater;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.EditText;
导入android.widget.ListView;
导入android.widget.TextView;
导入android.widget.Toast;
import co.uk.company.application.R;
import co.uk.company.application.injected.ApplicationGlobalState;
import co.uk.company.application.ui.companyActivity;
导入co.uk.company.application.ui.dialog.YesNoAlertDialogCreator;
import co.uk.company.sources.telnet.WifiTelnetClass;
导入com.google.inject.inject;
导入java.util.ArrayList;
导入java.util.Vector;
导入roboguice.inject.InjectView;
公共类WifiapActivity扩展了companyActivity{
@注入私有ApplicationGlobalState ApplicationGlobalState;
@InjectView(R.id.wifi_网络_列表)私有列表视图列表视图1;
专用无线信道;
选择专用无线信道;
私有数组列表数据;
私有arraylistdataold;
专用向量机;
专用无线适配器;
私有RealtimeUpdateScreen RealtimeUpdateScreen;
私有AdapterView.OnItemClickListener侦听器;
@凌驾
创建时的公共void(Bundle savedInstanceState){
Log.w(“,”onCreate(…)start”);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u wifi\u网络);
listener=new AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView arg0、视图arg1、最终整型arg2、长型arg3){
arg0.showContextMenuForChild(arg1);
//if(adapter.getItem(arg2.toString().endsWith(“.txt”))
Toast.makeText(getApplicationContext()、getString(R.string.loading)、Toast.LENGTH\u LONG.show();
}
};
dataold=newarraylist();
数据=新的ArrayList();
WificChannel=applicationGlobalState.WificCurrentChannel;
if(wifiChannels!=null)
对于(WifiChannel chn:wifiChannels.getChannels()){
dataold.add(chn);
添加数据(chn);
}
WificChannel=applicationGlobalState.WificCurrentChannel 5GHz;
if(wifiChannels!=null)
对于(WifiChannel chn:wifiChannels.getChannels()){
dataold.add(chn);
添加数据(chn);
}
适配器=新的WifiapAdapter(此,R.layout.wifi\u网络\u项目\u行,数据);
listView1.setAdapter(适配器);
listView1.setItemsCanFocus(false);
registerForContextMenu(listView1);
listView1.setOnItemClickListener(listener);
Log.w(“,”onCreate(…)finish”);
}
@凌驾
恢复时公开作废(){
Log.w(“,”onResume()start“);
super.onResume();
//realtimeUpdateScreen=新的realtimeUpdateScreen();
//execute(新对象());
Log.w(“,”onResume()finish”);
}
@凌驾
公共无效暂停(){
super.onPause();
realtimeUpdateScreen.cancel(true);
realtimeUpdateScreen=null;
Log.w(“,”onPause()finish“);
}
@凌驾
public void onCreateContextMenu(ContextMenu菜单,视图v,ContextMenu.ContextMenuInfo菜单信息){
Log.w(“,”onCreateContextMenu”);
AdapterView.AdapterContextMenuInfo信息=(AdapterView.AdapterContextMenuInfo)菜单信息;
//setHeaderTitle(fileNames.get(info.position));
channelSelected=数据获取(信息位置);
menu.add(menu.NONE,0,0,“Connect”);
menu.add(menu.NONE,1,1,“断开”);
menu.add(menu.NONE,2,2,“不做任何事情”);
}
@凌驾
公共布尔值onContextItemSelected(MenuItem项){
Log.w(“,”onContextItemSelected”);
int menuItemIndex=item.getItemId();
//最终AdapterView.AdapterContextMenuInfo信息=(AdapterView.AdapterContextMenuInfo)项。getMenuInfo();
开关(menuItemIndex){
案例0:
final AlertDialog.Builder alert=新建AlertDialog.Builder(此);
LayoutInflater li=LayoutInflater.from(this);
View promptsView=li.inflate(R.layout.dialog_与_文本_字段,空);
alert.setView(promptsView);
final TextView SSIDfield=(TextView)promptsView.findViewById(R.id.ssid_字段);
最终EditText输入2=(EditText)promptsView.findViewById(R.id.password_字段);
SSIDfield.setText(channelSelected.getName());
//最终按钮OK按钮=(按钮)promptsView.findViewById(R.id.wifi\u按钮\u yes);
//最终按钮cancelButton=(按钮)promptsView.findViewById(R.id.wifi\u按钮\u编号);
//okButton.setOnClickListener(新视图.OnClickListener(){
//@覆盖
//公共void onClick(视图arg0){
//
//                    }
//                });
//
//cancelButton.setOnClickListener(新视图.OnClickListener(){
//@覆盖
//公共void onClick(视图arg0){
////警惕。
//                    }
//                });
警报。设置积极按钮(“OK”,
新建DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id){