저는 문제가 있습니다. 즉, 토글 스위치를 사용하면 listview의 마지막 항목에서만 작동합니다. 전환 할 스위치는 중요하지 않습니다. 나는 다른 질문을 연구하지만 나는 그것을 이해할 수 없었다.listview 토글 스위치는 마지막 행에서만 작동합니다.
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView = inflater.inflate(R.layout.row, parent, false);
String allData = getItem(position);
final Switch status = (Switch) customView.findViewById(R.id.switchStatus);
status.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
Toast.makeText(getContext(),"selectid",Toast.LENGTH_LONG).show();
}
});
return customView;
}
여기서 내 어댑터를 볼 수 있습니다.
public class adapter_test extends ArrayAdapter<String> {
public adapter_allservicerecords(Context context, String[] data){
super(context, R.layout.row, data);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView = inflater.inflate(R.layout.row, parent, false);
String allData = getItem(position);
try {
if(!all_data.isEmpty()) {
JSONObject jsonRowData = new JSONObject(all_data);
try {
text.setText(jsonRowData.getString("TITLE"));
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
Log.e("FAILED", "Json parsing error: " + e.getMessage());
}
return customView;
}
}
답장을 보내 주셔서 감사합니다. 항목 item = getItem (position); gaves 오류 : (48, 28) 오류 : 호환되지 않는 유형 : 문자열을 오류로 변환 할 수 없습니다. – user7732643
좋아요, 당신이해야 할 일은 Item 생성자의 String 데이터를 전달하는 것입니다. –
여전히 같은 친구. – user7732643