1
현재 코드는 다음과 같습니다 ... 그리고 토스트에있는 메시지를 표시 할 수없는 문제가 있습니다 ....해결책이 필요합니다. 메시지가 토스트를 보여주지 않습니다.
아무 방법으로 어떤 방법으로 도와 줄 수 있습니까? 또는 컨텍스트 내가 여기서 사용해야합니까?
서버에 성공적으로 연결되었지만 콘솔에 응답이 있지만 토스트 메시지에 표시 할 수 없습니다.
public class MyActivity extends ActionBarActivity {
private Socket client;
Context c;
String userInput;
TextView txtV;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
txtV = (TextView)findViewById(R.id.txtView);
MyConnection sendMessageTask = new MyConnection();
sendMessageTask.execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
private class MyConnection extends AsyncTask<Void, Void, Void> {
String userInput;
Context c1;
@Override
protected Void doInBackground(Void... params) {
try {
client = new Socket("10.10.0.122", 1978); // connect to the server
BufferedReader stdIn = new BufferedReader(new InputStreamReader(client.getInputStream()));
while (true)
{
userInput = stdIn.readLine();
System.out.println(userInput);
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
Toast.makeText(c,userInput,Toast.LENGTH_LONG).show();
}
}
}
샘플 코드가 있습니까? –
왜 이것이 토스트 @EJP에 표시되지 않는가요? –