2011-11-11 3 views
0

Im 프로그래밍에 익숙하지 않아이 문제를 해결하기 위해 노력하고 있습니다. 태블릿의 각면에 두 개의 보이는 별도의 카운터를 만들려고합니다. 하나는 태블릿의 왼쪽이고 다른 하나는 태블릿의 오른쪽에 있습니다. 왼쪽 버튼을 클릭하면 왼쪽의 카운트가 업데이트됩니다 (예 : 1 + 1 + 1 등).하지만 오른쪽 카운터를 클릭하면 왼쪽 카운터에서 합계하는 값이 추가됩니다. (예를 들어, 오른쪽 클릭 (1 대신에, 2를 추가 한 후 난 내 코드는 지금까지Android 3.1, 두 개의 카운터를 나란히 표시하는 데 문제가 있습니다

import android.app.Activity; 
import android.os.Bundle; 
import android.content.Intent; 
import android.widget.Button; 
import android.widget.EditText; 
import android.view.View; 
import android.view.View.OnClickListener; 



public class swim2 extends Activity { 

// References to UI views 
EditText txtCount; 
EditText txtCount2; 
Button PUp; 
Button NUp; 


static int Count = 0; // Initial count 
static int Count2 = 0; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main3); 
    // TODO Auto-generated method stub 




     Button previous = (Button) findViewById(R.id.button4); 
     previous.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       Intent myIntent = new Intent(view.getContext(), swim1.class); 
        startActivityForResult(myIntent, 0); 
      } 

     }); 
    // Retrieve references to UI views by their id in XML layout 
     NUp = (Button)findViewById(R.id.incremintationbutton2);  
     txtCount2 = (EditText)findViewById(R.id.ni); 
     txtCount2.setText(String.valueOf(Count2)); //Set initial value 


     NUp = (Button)findViewById(R.id.incremintationbutton2); 
     // Process the button on-click event 
     NUp.setOnClickListener(new OnClickListener() { 

      public void onClick(View Button) { 
       Count++; 
       txtCount2.setText(String.valueOf(Count2)); 
      } 
     }); 
     PUp = (Button)findViewById(R.id.incremintationbutton1); 
     txtCount = (EditText)findViewById(R.id.pi); 
     txtCount.setText(String.valueOf(Count)); // Set initial value 

     PUp = (Button)findViewById(R.id.incremintationbutton1); 
     PUp.setOnClickListener(new OnClickListener() { 
       public void onClick(View Button) { 
        Count++; 
        txtCount.setText(String.valueOf(Count)); 
       } 
      }); 

} 

} 

답변

0

모양을

여기

이)가 같은 역할을하는 왼쪽 카운터를 클릭하면 1 추가 그것을 고치고, 카운트 ++ 중 하나를 count2 ++로 변경해야했다. 잠시 쉬었지만 커피 한 잔 후에 알아 냈다.

관련 문제