懇請各位高手大大們幫個忙
private static final String TAG = "MainActivity";
private Button mTotal;
private Button mChinese;
private Button mJapan;
private Button mSmail;
private Button mLove;
private Button mTotal1;
private Button mChinese1;
private Button mJapan1;
private Button mSmail1;
private Button mLove1;
private Button mSend;
private TextView mTotal2;
private TextView mChinese2;
private TextView mJapan2;
private TextView mSmail2;
private TextView mLove2;
int counter = 0;
int counter2 = 0;
int counter3 = 0;
int counter4 = 0;
int counter5 = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTotal1 = (Button) findViewById(R.id.button6);
mChinese1 = (Button) findViewById(R.id.button7);
mJapan1 = (Button)findViewById(R.id.button8);
mSmail1 = (Button)findViewById(R.id.button9);
mLove1 = (Button)findViewById(R.id.button10);
mTotal2 = (TextView) findViewById(R.id.textView);
mChinese2 = (TextView) findViewById(R.id.textView2);
mJapan2 = (TextView) findViewById(R.id.textView3);
mSmail2 = (TextView) findViewById(R.id.textView4);
mLove2 = (TextView) findViewById(R.id.textView5);
mTotal1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
counter++;
mTotal2.setText(String.valueOf(counter));
}
});
mChinese1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
counter2++;
counter2 = counter2 % 7;
mChinese2.setText(String.valueOf(counter2));
}
});
mJapan1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
counter3++;
counter3 = counter3 % 7;
mJapan2.setText(String.valueOf(counter3));
}
});
mSmail1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
counter4++;
counter4 = counter4 % 7;
mSmail2.setText(String.valueOf(counter4));
}
});
mLove1.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
counter5++;
counter5 = counter5 % 7;
mLove2.setText(String.valueOf(counter5));
}
});
}
上方這段程式碼與下方這段程式碼兩段是否可以合併如果不是請問題錯在哪?謝謝各位高手大大們
public class Client{
private Runnable Connection=new Runnable(){
@Override
public void run() {
// TODO Auto-generated method stub
try{
InetAddress serverIp = InetAddress.getByName("192.168.0.1");
int serverPort = 5050;
clientSocket = new Socket(serverIp, serverPort);
bw = new BufferedWriter( new OutputStreamWriter(clientSocket.getOutputStream()));
br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
while (clientSocket.isConnected()) {
tmp = br.readLine();
if(tmp!=null){
tmp=tmp.substring(tmp.indexOf("{"), tmp.lastIndexOf("}") + 1);
json_read=new JSONObject(tmp);
}
}
}catch(Exception e){
e.printStackTrace();
Log.e("text","Socket連線="+e.toString());
finish();
}
}
};
@Override
protected void onDestroy() {
super.onDestroy();
try {
json_write=new JSONObject();
json_write.put("action","離線");
Log.i("text","onDestroy()="+json_write+"\n");
bw.write(json_write+"\n");
bw.flush();
bw.close();
br.close();
clientSocket.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("text","onDestroy()="+e.toString());
}
}
}
}
}
謝謝各位高手大大們