-1
내 ListView에 문제가 있습니다. 새로 고침이 작동하지 않습니다. 누군가 나를 도울 수 있습니까? 각 조각에 조각이 있습니다. 이것들은 하나의 목록보기입니다. listitem을 클릭하면 값을 입력 할 수 있습니다. 어댑터의 데이터 집합을 새로 고치지 만 목록이 새로 고쳐지지 않습니다. 여기에 코드Android : adapter notifydatasetchanged does not work
:
public class ValuationActivity extends FragmentActivity {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
private static List<Ziel> goals = new ArrayList<Ziel>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_valuation);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
this.setTitle(ProjectsActivity.selectedProject.getKurzname());
this.getGoals();
mSectionsPagerAdapter.notifyDataSetChanged();
}
}
public static class DummySectionFragment extends Fragment {
private static TextView pointsTextView;
private static ProgressBar progressBar;
private static Ziel selectedGoal;
private static List<Ziel> tempGoalList;
private SimpleAdapter sAdapter;
private static ArrayList<HashMap<String, String>> dataList;
private static String[] from;
private static int[] to;
private static int nativeLayout;
private static ListView listView;
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_valuation_dummy, container, false);
tempGoalList = (ValuationActivity.goals.get((getArguments().getInt(ARG_SECTION_NUMBER)) - 1)).getSubgoals();
dataList = new ArrayList<HashMap<String, String>>(tempGoalList.size());
this.refreshGoalList(rootView);
progressBar = (ProgressBar) rootView.findViewById(R.id.progressBarValuation);
pointsTextView = (TextView) rootView.findViewById(R.id.textViewPointsLeft);
progressBar.setProgress(points);
pointsTextView.setText(points.toString() + getString(R.string.StringPointsLeft));
return rootView;
}
private void refreshGoalList(View rootView) {
tempGoalList = (ValuationActivity.goals.get((getArguments().getInt(ARG_SECTION_NUMBER)) - 1)).getSubgoals();
listView = (ListView) rootView.findViewById(id.listViewSubgoals);
refreshData();
from = new String[] { "name", "gewichtung" };
to = new int[] { android.R.id.text1, android.R.id.text2 };
nativeLayout = android.R.layout.simple_list_item_2;
sAdapter = new SimpleAdapter(getActivity(), dataList, nativeLayout, from, to);
listView.setAdapter(sAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
tempGoalList = (ValuationActivity.goals.get((getArguments().getInt(ARG_SECTION_NUMBER)) - 1)).getSubgoals();
AlertDialog.Builder valuationBox = new AlertDialog.Builder(getActivity());
selectedGoal = tempGoalList.get(arg2);
valuationBox.setTitle(selectedGoal.getName() + ": " + selectedGoal.getBeschreibung());
valuationBox.setMessage("Bitte geben Sie Ihre Bewertung ein. Sie haben noch " + points + " Punkte zur Verfügung.");
// Set an EditText view to get user input
final EditText input = new EditText(getActivity());
input.setInputType(InputType.TYPE_CLASS_NUMBER);
valuationBox.setView(input);
valuationBox.setPositiveButton("Bewerten", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
try {
Integer value = Integer.parseInt(input.getText().toString());
System.out.println("Eingegangene Bewertung: " + value);
points = points + selectedGoal.getGewichtung() - value;
selectedGoal.setGewichtung(value);
progressBar.setProgress(points);
pointsTextView.setText(points.toString() + getString(R.string.StringPointsLeft));
} catch (NumberFormatException nfe) {
System.out.println("Could not parse " + nfe);
}
// TODO - refresh GoalList
DummySectionFragment.refreshData();
sAdapter.notifyDataSetChanged();
}
});
valuationBox.create().show();
}
});
}
private static void refreshData() {
dataList.clear();
for (Ziel tempZiel : tempGoalList) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("name", tempZiel.getBeschreibung());
item.put("gewichtung", tempZiel.getGewichtung().toString() + " Punkte");
System.out.println(tempZiel.getBeschreibung() + ": " + tempZiel.getGewichtung());
dataList.add(item);
}
}
}
당신이 어댑터 데이터 집합을 업데이트하고 어디? 게시 한 코드에 표시되지 않습니다. 업데이트 된 데이터 세트를 버리는 새로 고침 코드를 보여줍니다. – laalto
좋아요, refreshData 메소드를 업데이트했습니다. 이제 목록은 지워집니다. 하지만 나를 위해 일하지 않는다 :( – user1803153