문자열 배열이 있으며 listView에 표시된 내용입니다. 그러나 나는 각 행에 int 배열을 할당해야하므로 클릭 할 때 "total_pts"사용자에서 뺀 다음 totalPoints textview에 표시됩니다.Java에서 값을 표시하지 않고 각 행의 값을 설정하는 방법
여기에 여기
int total_pts =0;
TextView totalPoints = (TextView)findViewById(R.id.totalP);
ListView에있다 : 다음 텍스트 뷰와 총 포인트 변수입니다
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, redeem);
//assign to listview
list.setAdapter(adapter);
//click listener
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//ListView Clicked item index
int itemPosition = position;
int[] points = new int[]{120,150,200,200,300,400,600};
if (total_pts >= points){
//where I am stuck...the conditional statement won't work because I
//am unsure how to say the points(value) at a certain index
//(the index clicked) and then subtract them and then display them
total_pts-=points;
totalPoints.text = "Total Points: \(Total_Points)"
}
}
});
매우 불분명하지만 원하는 것처럼 보입니다. if (total_pts> = points [position]) {total_pts- = points [position]; // ..other code}' –
나는 안드로이드 스튜디오를 새로 고치고 코드를 사용했다. 그것은 당신이 대답으로 남겨 두는 경우에 나는 정확한 것으로 표시 할 수 있습니다. 감사합니다. –