अभी मैं अपने सूची दृश्य को अपडेट करने के लिए setAdapter का उपयोग करता हूं, लेकिन मुझे लगता है कि notifiyDatasetChanged() का उपयोग करने का उचित तरीका है और मैं इसे अपने मुख्य वर्ग (यह एडाप्टर में) में काम करने के लिए नहीं मिल सकता है। यहाँ त्रुटि है:मैं ListAdapter के साथ काम करने के लिएडेटाडेटेड() को सूचित कैसे करूं?
विधि notifyDatasetChanged() प्रकार ListAdapter
मैं वहाँ ऐसा करने का एक बेहतर तरीका है अनुमान लगा रहा हूँ के लिए अपरिभाषित है - किसी को भी सही दिशा में मुझे बात कर सकते हैं? है एडाप्टर
public class ScoreList extends SherlockFragmentActivity {
private ListView listViewScore;
static List<Score> listScore = new ArrayList<Score>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.score_list);
ctx = this;
listScore = dbh.getAllScores();
listViewScore = (ListView) findViewById(R.id.score_list);
listViewScore.setAdapter(new ScoreListAdapter(ctx,
R.layout.score_row_item, listScore));
listViewScore.getAdapter().notifyDatasetChanged(); //this is where I get the error
}
}
यहाँ:
यहाँ मेरी कोड के प्रासंगिक भागों है
public class ScoreListAdapter extends ArrayAdapter<Score> {
private int resource;
private LayoutInflater inflater;
public ScoreListAdapter(Context ctx, int resourceId, List<Score> objects) {
super(ctx, resourceId, objects);
resource = resourceId;
inflater = LayoutInflater.from(ctx);
//context = ctx;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = (LinearLayout) inflater.inflate(resource, null);
Score score = getItem(position);
TextView txtName = (TextView) convertView.findViewById(R.id.name);
txtName.setText(score.getName());
TextView txtScoreChange = (TextView) convertView
.findViewById(R.id.scoreChange);
int scoreChange = Integer.parseInt(score.getScoreChange());
if (scoreChange > 0)
txtScoreChange.setText("+" + scoreChange);
else if (scoreChange < 0)
txtScoreChange.setText("" + scoreChange);
else
txtScoreChange.setText("");
TextView txtScoreTotal = (TextView) convertView
.findViewById(R.id.scoreTotal);
txtScoreTotal.setText(score.getScoreTotal());
final LinearLayout currentRow = (LinearLayout) convertView
.findViewById(R.id.scoreRowLayout);
notifyDataSetChanged();
return convertView;
}
}
यह 'सूचित करेंडेटाट चेंज()' - नोटिस पूंजी एस। आपके पास दिखाए गए लाइन पर आपके पास एक लोअर केस है। – Squonk
सबसे पहले आपको सूचित करने के उपयोग की आवश्यकता हैडेटाडेटेड ... संलग्न पर्यवेक्षकों को सूचित करता है कि अंतर्निहित डेटा बदल दिया गया है और डेटा सेट को प्रतिबिंबित करने वाले किसी भी दृश्य को स्वयं को ताज़ा करना चाहिए। लागू करने से पहले इसे समझें ... अधिसूचना डेटासेट चेंज() का उपयोग तब किया जाएगा जब आपके एडाप्टर डेटा में डेटा अपडेट किया गया हो या बस बदला गया .. यह एडाप्टर से जुड़ा संग्रह बदल गया है। सृजन में इसे कॉल करने की कोई आवश्यकता नहीं – Pragnani
धन्यवाद, मैंने बहुत सारे कोड काट दिया है, इसलिए मैं इसे सृजन पर नहीं बुला रहा था, यह सिर्फ उस तरह से देखा गया। – GrilledCheese