ListView に問題があります。リフレッシュが機能していません。誰かが私を助けることができますか?私はいくつかのフラグメントを取得しました。それぞれにこれらは1つのリストビューです。リスト項目をクリックすると、値を入力できます。アダプターのデータセットを更新しましたが、リストが更新されません。
ここにコード:
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);
}
}
}