gpt4 book ai didi

java - onItemClick 单击时不起作用

转载 作者:行者123 更新时间:2023-12-01 14:58:54 26 4
gpt4 key购买 nike

我错过了一些非常重要的东西,但我不太明白是什么。有人可以帮忙吗?这可能是我错过的一些非常愚蠢的事情,但我无法启动我的 onItemClick。

创建时....

    @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
actu_ip = intent.getStringExtra(IPEntry.ACTUALSMARTIP);
setContentView(R.layout.act_ipcontrol);

mainListView = (ListView) findViewById( R.id.mainListView );
String[] options = new String[] { "All in to 1", "Spare"};

ArrayList<String> optionsList = new ArrayList<String>();
optionsList.addAll( Arrays.asList(options) );
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, optionsList);
mainListView.setAdapter( listAdapter );

try {
Toast.makeText(IPControl.this, "Please wait...Connecting...", Toast.LENGTH_SHORT).show();
new AsyncAction().execute();
} catch(Exception e) {
e.printStackTrace();
}
}

private class AsyncAction extends AsyncTask<String, Void, String> {
protected String doInBackground(String... args) {
try {
InetAddress serverAddr = InetAddress.getByName(actu_ip);
socket = new Socket(serverAddr, REDIRECTED_SERVERPORT);
OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream());
BufferedWriter bw = new BufferedWriter(osw);
out = new PrintWriter(bw, true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while (! in .ready());
readBuffer();
out.println("root\r\n");
while (! in .ready());
readBuffer();
out.println("root\r\n");
while (! in .ready());
readBuffer();
out.println("[verbose,off\r\n");
while (! in .ready());
String msg = "";
while ( in .ready()) {
msg = msg + (char) in .read();
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return null;//returns what you want to pass to the onPostExecute()
}

protected void onPostExecute(String result) {

Toast.makeText(IPControl.this, "Connected", Toast.LENGTH_SHORT).show();

//results the data returned from doInbackground

IPControl.this.data = result;

}
}

private String readBuffer() throws IOException {
String msg = "";

while(in.ready()) {
msg = msg + (char)in.read();
}
//System.out.print(msg);
if(msg.indexOf("SNX_COM> ") != -1) return msg.substring(0, msg.indexOf("SNX_COM> "));
else if(msg.indexOf("SCX_COM> ") != -1) return msg.substring(0, msg.indexOf("SCX_COM> "));
else return msg;
}
}

我想要启动什么...

        public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {

try {
new AsyncAction1().execute();
} catch(Exception e) {
e.printStackTrace();
}
}

private class AsyncAction1 extends AsyncTask<String, Void, String> {
protected String doInBackground(String... args) {
try {
out.println("[c,l#,i1,o*\r\n");
//System.out.print("root\r\n");
while(! in .ready());


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

return null;//returns what you want to pass to the onPostExecute()
}

protected void onPostExecute(String result) {

//results the data returned from doInbackground
Toast.makeText(IPControl.this, "Command Sent", Toast.LENGTH_SHORT).show();

IPControl.this.data = result;

}
}

最佳答案

我在您的代码中没有看到 listview 的 setOnItemClickListener 方法。你实现了吗?尝试以下操作

mainListView.setAdapter( listAdapter ); 
mainListView.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {

try {
new AsyncAction1().execute();
}catch(Exception e) {
e.printStackTrace();
}
});

关于java - onItemClick 单击时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13976526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com